﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Collections;
using System.ComponentModel;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Xml;
using System.IO;
using System.Text;
using System.Transactions;
using WebServiceSmart.Router;
using Thrift.Transport;
using Thrift.Protocol;
using Thrift.Route;
using System.Runtime.InteropServices;
using System.Collections.Generic;
using log4net;
using System.Security.Cryptography;
using System.Net;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Threading;
using WebServiceSmart.Model;
using MySql.Data.MySqlClient;
using System.Drawing;
using WebServiceShopping;
using WebServiceShopping.Thrift;
using static WebServiceShopping.wechartTools;
using System.Web.UI.WebControls.WebParts;

namespace WebServiceSmart
{
    public partial class MyService
    {
        private const string BIAOUSERREPAIR = "s_userrepair";


        private const string S_LDPCONFIG = "s_ldpconfig";
        private const string COMPANYBANKCARD = "company_bankcard";

        private const string SQLYONGHUREPAIR = "repair_id,repair_createtime,repair_yonghuid,repair_yonghuname," +
        "repair_yonghuphone,repair_companyid,repair_companyname,repair_service,repair_yhlongitude," +
        "repair_yhlatitude,repair_status1,repair_status2,repair_status3,repair_carinfo,repair_carplate," +
        "repair_repairpic_ids,repair_repairinfo,repair_repairinfo_products,repair_xunjiaid,repair_baojiaid," +
        "repair_serviceprice,repair_productprice,repair_gongshiprice,repair_allprice," +
        "repair_paystatus,repair_default";

        [WebMethod(Description = "首页初进入接口")]
        //首页登录获取数据
        public string YongHu_FristInterFace(string msg)
        {
            ILog loginfo = LogManager.GetLogger("LoggerJieKou");
            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);
            mysqlcli mainsql = new mysqlcli();
            mainsql.openShopServicesql();

            try
            {
                var type = comrcv.Map_Args["type"];
                string yonghu_longitude = "";
                string yonghu_latitude = "";
                if (comrcv.Map_Args.ContainsKey("longitude"))//是否传定位进行查询
                {
                    yonghu_longitude = comrcv.Map_Args["longitude"];
                    yonghu_latitude = comrcv.Map_Args["latitude"];
                }
                var cid = comrcv.Map_Args.ContainsKey("c_id") ? comrcv.Map_Args["c_id"] : "";

                string repair_yonghuid = comrcv.Map_Args.ContainsKey("yonghuid") ? comrcv.Map_Args["yonghuid"] : "";


                ret.Maplist_MapArgs = new Dictionary<string, List<Dictionary<string, string>>>();
                ret.Maplist_MapArgs.Add("TypeDatas", mainsql.SqlExcuteWithReturn($"select * from {BIAOSHOPCONFIG} where c_type='{type}' {(type == "banner" ? "" : "and c_parent_id is not null")} order by c_index").ToModels());


                string julistr = string.Format("select shop.* from( " +
               "select * , round(st_distance_sphere(point({0},{1}), point(`user_longitude`,`user_latitude`))) dis " +
               "from {2} having dis < 500000 ) shop ", yonghu_longitude, yonghu_latitude, BIAOUSERCOMPANY);
                string cmd = string.Format("select t1.*,t2.* from ({0}) t1 left join {1} t2 on t1.user_mentou=t2.file_id  WHERE t1.user_status ='1' order by dis limit 2;", julistr, BIAOSHOPFILE);

                var ds = mainsql.SqlExcuteWithReturn(cmd);

                ret.Maplist_MapArgs.Add("CompanyDatas", ds.ToModels());


                StringBuilder sql = new StringBuilder();
                sql.AppendFormat("select * from (select t1.*,t3.h_id as h_configid,t3.h_index as c_index,t2.file_small_path from {2} t3 inner join {0} t1 on t3.prd_id=t1.prd_id left join {1} t2 on t1.prd_cover_id=t2.file_id) as tb",
                    BIAOPRODUCT, BIAOSHOPFILE, BIAOHUODONGPRD, DateTime.Now.ToString("yyyy-MM-dd"));
                if (string.IsNullOrWhiteSpace(cid))
                {
                    sql.Append(" where h_configid='1'");
                    sql.Append(" order by c_index,prd_index desc");
                    sql.Append(" limit 0,9");
                }
                else
                {
                    sql.Append(" where h_configid='" + cid + "'");
                    sql.Append(" order by c_index,prd_index desc");
                }

                var lis = mainsql.SqlExcuteWithReturn(sql.ToString()).ToModels();
                ret.Maplist_MapArgs.Add("ProductDatas", lis);
                ret.Map_Args.Add("IsTanChuang", "0");
                ret.Map_Args.Add("TanChuangamount", "0");

                if (repair_yonghuid != "")
                {
                    string sqlwhere = string.Format("WHERE t1.repair_yonghuid ='{0}' AND t1.repair_status1 <> '6' AND t1.repair_status1 <> '0' ", repair_yonghuid);

                    ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0}  t1 left join  {2} t2 on t1.repair_companyid=t2.user_id  {1} ;", BIAOUSERREPAIR, sqlwhere, BIAOUSERCOMPANY));


                    lis = ds.ToModels();

                    ret.Maplist_MapArgs.Add("RepairDatas", lis);

                    var time = DateTime.Now.ToString("yyyy-MM").Substring(0, 7) + "-01";
                    var starttime = time;
                    var endtime = time.ToDateTime().Value.AddMonths(1).ToString("yyyy-MM-dd");
                    var list = mainsql.SqlExcuteWithReturn($"select t1.*,t2.user_name,t2.user_phone from {BIAOXUNJIA + time.ToDateTime().Value.ToString("yyyyMM")} t1 left join {BIAOUSER} t2 on t1.user_id=t2.user_onlyid where x_deleteflag=0 and x_send_time >='{starttime}' and x_send_time<'{endtime}' and user_id='{repair_yonghuid}' order by x_send_time desc").ToModels();
                    ret.Maplist_MapArgs.Add("XunJiaRepairDatas", list);

                    ret.Maplist_MapArgs.Add("CarDatas", mainsql.SqlExcuteWithReturn($"select * from {USERCAR} where car_userid='{repair_yonghuid}'; ").ToModels());

                    //string sqlcmd = string.Format("SELECT *  FROM {0} where yhq_useronlyid='{1}' AND yhq_type='0' ;",
                    //    BIAOALLYOUHUIQUAN, repair_yonghuid);
                    //ds = mainsql.SqlExcuteWithReturn(sqlcmd);
                    //if (ds.Rows.Count == 0)
                    //{
                    //    //     ret.Map_Args["IsTanChuang"] = "0";
                    //    //    ret.Map_Args["TanChuangamount"] = "0";
                    //}

                    //未读消息
                    string chatrecordSql = $"select count(*) from s_chatrecord where chart_isread='0' and chart_from_user_id='{repair_yonghuid}' and user_id='{repair_yonghuid}'; ";
                    loginfo.Info(chatrecordSql);
                    var chatrecordCount = mainsql.SqlExcuteWithReturn(chatrecordSql).ToInt32();
                    ret.Map_Args["ChatRecordCount"] = chatrecordCount.ToString();
                }

                //获取门店商品活动信息
                var sqlcpm = $@"select e.file_small_path as company_path,c.commpdity_type_name,d.user_name,d.user_phone, b.*, a.* from s_commodity a 
                        left join s_usercompany b on a.company_id=b.user_id
	                    left join s_files e on b.user_mentou=e.file_id 
                        left join s_commpditytype c on a.commpdity_type_id=c.commpdity_type_id
                        left join yonghualluser d on a.commodity_create_user=d.user_onlyid
                        right join (select commodity_id from s_huodongcommodity GROUP BY commodity_id) e on e.commodity_id = a.commodity_id 
                        where commodity_isdel=0 and commodity_status=1 order by commodity_create_time desc";

                var result = mainsql.SqlExcuteWithReturn(sqlcpm).ToModels();
                result.ForEach(t =>
                {
                    t["file_small_path"] = "";

                    if (!string.IsNullOrWhiteSpace(t["commodity_file_id"]))
                    {
                        var ids = t["commodity_file_id"].Split(',');

                        if (ids.Length > 0)
                        {
                            t["file_small_path"] = mainsql.SqlExecuteScalar($"select file_path from s_files where file_id='{ids[0]}' limit 0,1").ToString();
                        }
                    }
                });
                ret.Maplist_MapArgs.Add("Commoditys", result);

                mainsql.closesql();
                ret.Byte_Flag = (sbyte)1;
            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                loginfo.Info(ex);
            }
        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }

        #region 非WEB接口

        private static string GetLdpLiushui(mysqlcli mainsql)
        {

            string sqlcmd = string.Format("SELECT * from {0} where com_account='qingguan' AND com_number='00000' ;", BIAOQGZHIFUCOMPANY);
            DataTable ds = mainsql.SqlExcuteWithReturn(sqlcmd);

            string qgnumber = ds.Rows[0]["com_number"].ToString();
            string qgnumberdate = ds.Rows[0]["com_numberdate"].ToString();

            string nowdate = DateTime.Now.ToString("yyyyMMdd");

            int Goodscount = 1;
            string oldid = "";
            string olddate = "";
            oldid = qgnumberdate;
            try
            {
                olddate = oldid.Substring(0, 8);
            }
            catch
            {

            }
            if (nowdate == olddate)
            {
                string countstr = oldid.Remove(0, 8);
                int.TryParse(countstr, out Goodscount);
                Goodscount++;
            }
            else
            {
                Goodscount = 1;
            }
            string command = string.Format("update {0} set com_numberdate='{1}' WHERE com_account='qingguan' ",
                BIAOQGZHIFUCOMPANY, nowdate + Goodscount.ToString());
            mainsql.SqlExcuteNoReturn(command);

            return qgnumber + DateTime.Now.ToString("yyyyMMddHHmmss") + Goodscount.ToString("D4");
        }
        //推广分润
        public void tuiguangfenrun(mysqlcli mainsql, double repair_productprice, string yonghuid, string repair_id = "")
        {
            ILog loginfo = LogManager.GetLogger("LoggerJieKou");
            string sqlwhere = string.Format(" select * from {0} WHERE user_onlyid ='{1}' ", BIAOYONGHUUSER, yonghuid);

            var ds = mainsql.SqlExcuteWithReturn(sqlwhere);
            if (ds.Rows.Count == 0)
            {
                return;
            }
            string zhuguiguang = ds.Rows[0]["user_othertuiguangid"].ToString();

            sqlwhere = string.Format(" select * from {0} WHERE user_tuiguangid ='{1}' ", BIAOYONGHUUSER, zhuguiguang);

            ds = mainsql.SqlExcuteWithReturn(sqlwhere);
            if (ds.Rows.Count == 0)
            {
                return;
            }
            int tuiguanglevel = ds.Rows[0]["user_tuiguanglevel"].ToInt32();
            double tuiguangbili1 = 0, tuiguangbili2 = 0, tuiguangbili3 = 0;
            string yonghuid1 = "", yonghuid2 = "", yonghuid3 = "";
            string yonghuphone1 = "", yonghuphone2 = "", yonghuphone3 = "";
            if (tuiguanglevel == 1)
            {
                double bili1 = ds.Rows[0]["user_tuiguangbili"].ToDouble();
                yonghuphone1 = ds.Rows[0]["user_phone"].ToString();
                yonghuid1 = ds.Rows[0]["user_onlyid"].ToString();

                tuiguangbili1 = bili1;
                loginfo.Info("1---" + tuiguangbili1.ToString());
            }
            else if (tuiguanglevel == 2)
            {
                string user_othertuiguangid = ds.Rows[0]["user_othertuiguangid"].ToString();
                double bili1 = ds.Rows[0]["user_tuiguangbili"].ToDouble();
                yonghuphone2 = ds.Rows[0]["user_phone"].ToString();
                yonghuid2 = ds.Rows[0]["user_onlyid"].ToString();

                ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} WHERE user_tuiguangid = '{1}' ;", BIAOYONGHUUSER, user_othertuiguangid));
                double bili2 = ds.Rows[0]["user_tuiguangbili"].ToDouble();

                yonghuphone1 = ds.Rows[0]["user_phone"].ToString();
                yonghuid1 = ds.Rows[0]["user_onlyid"].ToString();

                tuiguangbili2 = bili1 * bili2;
                tuiguangbili2 = Math.Round(tuiguangbili2, 3);

                tuiguangbili1 = bili2;
                loginfo.Info("2---" + tuiguangbili1.ToString() + "--" + tuiguangbili2.ToString());
            }
            else if (tuiguanglevel == 3)
            {
                string user_othertuiguangid = ds.Rows[0]["user_othertuiguangid"].ToString();
                double bili1 = ds.Rows[0]["user_tuiguangbili"].ToDouble();
                yonghuphone3 = ds.Rows[0]["user_phone"].ToString();
                yonghuid3 = ds.Rows[0]["user_onlyid"].ToString();

                ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} WHERE user_tuiguangid = '{1}' ;", BIAOYONGHUUSER, user_othertuiguangid));
                double bili2 = ds.Rows[0]["user_tuiguangbili"].ToDouble();
                user_othertuiguangid = ds.Rows[0]["user_othertuiguangid"].ToString();
                yonghuphone2 = ds.Rows[0]["user_phone"].ToString();
                yonghuid2 = ds.Rows[0]["user_onlyid"].ToString();

                ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} WHERE user_tuiguangid = '{1}' ;", BIAOYONGHUUSER, user_othertuiguangid));
                double bili3 = ds.Rows[0]["user_tuiguangbili"].ToDouble();
                yonghuphone1 = ds.Rows[0]["user_phone"].ToString();
                yonghuid1 = ds.Rows[0]["user_onlyid"].ToString();

                tuiguangbili3 = bili1 * bili2 * bili3;
                tuiguangbili3 = Math.Round(tuiguangbili3, 3);

                tuiguangbili2 = bili2 * bili3;
                tuiguangbili2 = Math.Round(tuiguangbili2, 3);

                tuiguangbili1 = bili3;
                loginfo.Info("3---" + tuiguangbili1.ToString() + "--" + tuiguangbili2.ToString() + "--" + tuiguangbili3.ToString());
            }
            else
            {
                return;
            }

            if (tuiguangbili1 != 0)
            {

                tuiguangbili1 = tuiguangbili1 - tuiguangbili2;
                loginfo.Info("111---" + tuiguangbili1.ToString());
                loginfo.Info("111---" + repair_productprice.ToString());
                double tuiguangprice = repair_productprice * tuiguangbili1;
                loginfo.Info("111---" + tuiguangprice.ToString());
                tuiguangprice = Math.Round(tuiguangprice, 2);
                string qgliushuinumber = GetLdpLiushui(mainsql);
                sqlwhere = string.Format("INSERT INTO {0} (zf_time,zf_type,zf_status,zf_qgnumber," +
                 "zf_zfonlyid,zf_zfphone,zf_yhamount,zf_default,zf_way,zf_shouzhi,zf_comshouzhi,zf_companyname)" +
                 " VALUES ('{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','零钱','1','1','平台返现')",
                 BIAOQGZHIFURECORD + DateTime.Now.ToString("yyyyMM"), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "推广分成", "支付成功", qgliushuinumber,
                 yonghuid1, yonghuphone1, tuiguangprice.ToString("0.00"), "推广分成" + repair_id, "平台");
                int sqlret = mainsql.SqlExcuteNoReturn(sqlwhere);
                sqlwhere = string.Format(" update {0} set user_balance=user_balance+{1} where user_onlyid ='{2}' ;", BIAOYONGHUUSER, tuiguangprice.ToString("0.00"), yonghuid1);
                sqlret = mainsql.SqlExcuteNoReturn(sqlwhere);
            }

            if (tuiguangbili2 != 0)
            {
                tuiguangbili2 = tuiguangbili2 - tuiguangbili3;
                loginfo.Info("222---" + tuiguangbili2.ToString());
                double tuiguangprice = repair_productprice * tuiguangbili2;
                tuiguangprice = Math.Round(tuiguangprice, 2);
                string qgliushuinumber = GetLdpLiushui(mainsql);
                sqlwhere = string.Format("INSERT INTO {0} (zf_time,zf_type,zf_status,zf_qgnumber," +
                 "zf_zfonlyid,zf_zfphone,zf_yhamount,zf_default,zf_way,zf_shouzhi,zf_comshouzhi,zf_companyname)" +
                 " VALUES ('{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','零钱','1','1','平台返现')",
                 BIAOQGZHIFURECORD + DateTime.Now.ToString("yyyyMM"), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "推广分成", "支付成功", qgliushuinumber,
                 yonghuid2, yonghuphone2, tuiguangprice.ToString("0.00"), "推广分成" + repair_id, "平台");
                int sqlret = mainsql.SqlExcuteNoReturn(sqlwhere);
                sqlwhere = string.Format(" update {0} set user_balance=user_balance+{1} where user_onlyid ='{2}' ;", BIAOYONGHUUSER, tuiguangprice.ToString("0.00"), yonghuid2);
                sqlret = mainsql.SqlExcuteNoReturn(sqlwhere);
            }

            if (tuiguangbili3 != 0)
            {
                loginfo.Info("333---" + tuiguangbili3.ToString());
                double tuiguangprice = repair_productprice * tuiguangbili3;
                tuiguangprice = Math.Round(tuiguangprice, 2);
                string qgliushuinumber = GetLdpLiushui(mainsql);
                sqlwhere = string.Format("INSERT INTO {0} (zf_time,zf_type,zf_status,zf_qgnumber," +
                 "zf_zfonlyid,zf_zfphone,zf_yhamount,zf_default,zf_way,zf_shouzhi,zf_comshouzhi,zf_companyname)" +
                 " VALUES ('{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','零钱','1','1','平台返现')",
                 BIAOQGZHIFURECORD + DateTime.Now.ToString("yyyyMM"), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "推广分成", "支付成功", qgliushuinumber,
                 yonghuid3, yonghuphone3, tuiguangprice.ToString("0.00"), "推广分成" + repair_id, "平台");
                int sqlret = mainsql.SqlExcuteNoReturn(sqlwhere);
                sqlwhere = string.Format(" update {0} set user_balance=user_balance+{1} where user_onlyid ='{2}' ;", BIAOYONGHUUSER, tuiguangprice.ToString("0.00"), yonghuid3);
                sqlret = mainsql.SqlExcuteNoReturn(sqlwhere);
            }
        }
        //获取推广顺序号
        public string gettuiguangcount(mysqlcli mainsql)
        {
            var ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} WHERE config_name = 'config_tuiguangcount' ;", S_LDPCONFIG));
            int config_value = ds.Rows[0]["config_value"].ToInt32();
            config_value++;
            mainsql.SqlExcuteNoReturn(string.Format(" update {0} set config_value='{1}'  WHERE config_name = 'config_tuiguangcount' ;",
                S_LDPCONFIG, config_value));
            return config_value.ToString("D4");
        }

        //获取询价编号
        public string getxunjiaid(mysqlcli mainsql)
        {
            string xunjiaid = "";

            DataTable ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} WHERE  config_name='config_xunjiacount'  ;", S_LDPCONFIG));

            string xjid = ds.Rows[0]["config_value"].ToString();
            string yymm = xjid.Substring(0, 6);
            string stringcount = xjid.Remove(0, 6);
            if (yymm != DateTime.Now.ToString("yyyyMM"))
            {
                yymm = DateTime.Now.ToString("yyyyMM");
            }
            int xunjiacount = 0;
            int.TryParse(stringcount, out xunjiacount);
            xunjiacount++;
            xunjiaid = yymm + xunjiacount.ToString();

            mainsql.SqlExcuteNoReturn(string.Format(" update {0} set config_value='{1}'  WHERE config_name = 'config_xunjiacount' ;",
            S_LDPCONFIG, xunjiaid));
            return xunjiaid;
        }
        //获取维修编号
        public string getrepairid(mysqlcli mainsql)
        {
            string repairid = "";
            DataTable ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} WHERE  config_name='config_repaircount'  ;", S_LDPCONFIG));

            string xjid = ds.Rows[0]["config_value"].ToString();

            string yymmdd = "";
            string stringcount = "";
            if (xjid.Length > 8)
            {
                yymmdd = xjid.Substring(0, 8);
                stringcount = xjid.Remove(0, 8);
            }
            int repaircount = 0;
            int.TryParse(stringcount, out repaircount);
            repaircount++;

            if (yymmdd != DateTime.Now.ToString("yyyyMMdd"))
            {
                yymmdd = DateTime.Now.ToString("yyyyMMdd");
                repaircount = 1;
            }

            repairid = "WXD" + yymmdd + repaircount.ToString("D4");

            mainsql.SqlExcuteNoReturn(string.Format(" update {0} set config_value='{1}'  WHERE config_name = 'config_repaircount' ;",
            S_LDPCONFIG, yymmdd + repaircount.ToString("D4")));


            return repairid;
        }
        #endregion

        #region 查询接口

        [WebMethod(Description = "用户查询修理厂")]
        public string YongHu_GetCompany(string msg)
        {
            ILog loginfo = LogManager.GetLogger("LoggerJieKou");
            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);
            mysqlcli mainsql = new mysqlcli();
            mainsql.openShopServicesql();

            try
            {
                using (TransactionScope tsall = new TransactionScope())
                {

                    if (comrcv.Map_Args.ContainsKey("user_id") == false)
                    {
                        string sqlwhere = string.Format(" WHERE t1.user_status ='1' ");
                        string orderStr = "";
                        //user_company_type是否做有活动筛选0否1是
                        string user_company_type = comrcv.Map_Args["user_company_type"];
                        if (user_company_type.Equals("1"))//有活动
                        {
                            sqlwhere += " and user_company_type=1 ";
                        }
                        //排序方式 orderType 0距离最近,1评分最高
                        string orderType = string.IsNullOrEmpty(comrcv.Map_Args["orderType"]) ? "0" : comrcv.Map_Args["orderType"];
                        switch (orderType)
                        {
                            case "0"://距离最近
                                orderStr = " order by dis ";
                                break;
                            case "1"://评分最高
                                orderStr = "order by user_star  desc";
                                break;

                            default:
                                break;
                        }



                        if (comrcv.Map_Args["name"] != "")
                        {
                            sqlwhere = string.Format(" WHERE t1.user_companyname like '%{0}%' ", comrcv.Map_Args["name"]);
                            if (user_company_type.Equals("1"))//有活动
                            {
                                sqlwhere += " and user_company_type=1 ";
                            }
                            string yonghu_longitude = "";
                            string yonghu_latitude = "";
                            if (comrcv.Map_Args.ContainsKey("longitude"))//是否传定位进行查询
                            {
                                yonghu_longitude = comrcv.Map_Args["longitude"];
                                yonghu_latitude = comrcv.Map_Args["latitude"];
                            }
                            string julistr = string.Format("select shop.* from( " +
                            "select * , round(st_distance_sphere(point({0},{1}), point(`user_longitude`,`user_latitude`))) dis " +
                            "from {2}  ) shop  ", yonghu_longitude, yonghu_latitude, BIAOUSERCOMPANY);

                            loginfo.Info(string.Format("select t1.*,t2.* from ({0}) t1 left join {1} t2 on t1.user_mentou=t2.file_id  {2} {3} ;", julistr, BIAOSHOPFILE, sqlwhere.ToString(), orderStr));
                            var ds = mainsql.SqlExcuteWithReturn(string.Format("select t1.*,t2.* from ({0}) t1 left join {1} t2 on t1.user_mentou=t2.file_id  {2} {3} ;", julistr, BIAOSHOPFILE, sqlwhere.ToString(), orderStr));

                            ret.Maplist_MapArgs = new Dictionary<string, List<Dictionary<string, string>>>();

                            ret.Maplist_MapArgs.Add("Datas", ds.ToModels());


                        }
                        else
                        {

                            string yonghu_longitude = "";
                            string yonghu_latitude = "";
                            if (comrcv.Map_Args.ContainsKey("longitude"))//是否传定位进行查询
                            {
                                yonghu_longitude = comrcv.Map_Args["longitude"];
                                yonghu_latitude = comrcv.Map_Args["latitude"];
                            }
                            string julistr = string.Format("select shop.* from( " +
                            "select * , round(st_distance_sphere(point({0},{1}), point(`user_longitude`,`user_latitude`))) dis " +
                            "from {2} having dis < 500000 ) shop ", yonghu_longitude, yonghu_latitude, BIAOUSERCOMPANY);


                            var ds = mainsql.SqlExcuteWithReturn(string.Format("select t1.*,t2.* from ({0}) t1 left join {1} t2 on t1.user_mentou=t2.file_id  {2} {3} limit 50 ;", julistr, BIAOSHOPFILE, sqlwhere.ToString(), orderStr));

                            ret.Maplist_MapArgs = new Dictionary<string, List<Dictionary<string, string>>>();

                            ret.Maplist_MapArgs.Add("Datas", ds.ToModels());
                        }
                    }
                    else
                    {
                        string user_id = comrcv.Map_Args["user_id"];
                        var ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} where user_id ='{1}';", BIAOUSERCOMPANY, user_id));
                        if (ds.Rows.Count == 0)
                        {
                            mainsql.closesql();
                            ret.Map_Args["ErrorMsg"] = "店铺id有误";  //参数错误
                            goto EXIT;
                        }
                        ret.Maplist_MapArgs = new Dictionary<string, List<Dictionary<string, string>>>();
                        ret.Maplist_MapArgs.Add("Datas", ds.ToModels());

                        string picids = ds.Rows[0]["user_mentou"].ToString() + "," + ds.Rows[0]["user_scene"].ToString();
                        var ids = picids.Split(",".ToArray(), StringSplitOptions.RemoveEmptyEntries);

                        var files = mainsql.SqlExcuteWithReturn($"select file_id,file_path from {BIAOSHOPFILE} where file_id in('{string.Join("','", ids)}')   ").ToModels();

                        ret.Maplist_MapArgs.Add("Files", files);
                    }
                    mainsql.closesql();
                    tsall.Complete();
                    ret.Byte_Flag = (sbyte)1;
                }
            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                loginfo.Info(ex);
            }

        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }



        [WebMethod(Description = "根据修理厂ID查询修理厂详情")]
        public string YongHu_GetCompany_Info(string msg)
        {
            ILog loginfo = LogManager.GetLogger("LoggerJieKou");
            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);
            mysqlcli mainsql = new mysqlcli();
            mainsql.openShopServicesql();

            try
            {
                using (TransactionScope tsall = new TransactionScope())
                {
                    if (comrcv.Map_Args["sid"] != "")
                    {
                        string sqlwhere = string.Format(" where t1.Sid = '{0}' ", comrcv.Map_Args["sid"]);
                        string julistr = string.Format("select shop.* from( " +
                        "select *  " +
                        "from {0}  ) shop  ", BIAOUSERCOMPANY);
                        loginfo.Info(string.Format("select t1.*,t2.* from ({0}) t1 left join {1} t2 on t1.user_mentou=t2.file_id  {2}  ;", julistr, BIAOSHOPFILE, sqlwhere.ToString()));
                        var ds = mainsql.SqlExcuteWithReturn(string.Format("select t1.*,t2.* from ({0}) t1 left join {1} t2 on t1.user_mentou=t2.file_id  {2} ", julistr, BIAOSHOPFILE, sqlwhere.ToString()));
                        ret.Maplist_MapArgs = new Dictionary<string, List<Dictionary<string, string>>>();
                        ret.Maplist_MapArgs.Add("Datas", ds.ToModels());

                        var dts = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} where Sid ='{1}';", BIAOUSERCOMPANY, comrcv.Map_Args["sid"]));
                        if (dts.Rows.Count == 0)
                        {
                            mainsql.closesql();
                            ret.Map_Args["ErrorMsg"] = "店铺id有误";  //参数错误
                            goto EXIT;
                        }

                        string picids = dts.Rows[0]["user_mentou"].ToString() + "," + ds.Rows[0]["user_scene"].ToString();
                        var ids = picids.Split(",".ToArray(), StringSplitOptions.RemoveEmptyEntries);
                        var files = mainsql.SqlExcuteWithReturn($"select file_id,file_path from {BIAOSHOPFILE} where file_id in('{string.Join("','", ids)}')   ").ToModels();
                        ret.Maplist_MapArgs.Add("Files", files);
                        mainsql.closesql();
                        tsall.Complete();
                        ret.Byte_Flag = (sbyte)1;
                    }
                }
            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                loginfo.Info(ex);
            }

        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }






        [WebMethod(Description = "根据订单类型查询订单列表 1：维修单  2：订单  3：团购订单")]
        public string GetOrderByType(string msg)
        {
            ILog loginfo = LogManager.GetLogger("LoggerJieKou");
            loginfo.Info($"GetOrderByType：{msg}");

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);

            mysqlcli mainsql = new mysqlcli();

            mainsql.openShopServicesql();

            try
            {
                ret.Maplist_MapArgs = new Dictionary<string, List<Dictionary<string, string>>>();
                var orderType = comrcv.Map_Args["orderType"];//订单类型  1：维修单  2：订单  3：t团购订单
                var companyId = comrcv.Map_Args["companyId"];
                var userId = comrcv.Map_Args["userId"];//用户ID 
                var pageIndex = comrcv.Map_Args["pageIndex"].ToInt32();
                var pageSize = comrcv.Map_Args["pageSize"].ToInt32();

                pageIndex = pageIndex == 0 ? 1 : pageIndex;
                pageSize = pageSize == 0 ? 10 : pageSize;

                switch (orderType)
                {
                    case "1":
                        GetRepairOrderAll(mainsql, ret.Maplist_MapArgs, userId, pageIndex, pageSize);

                        //var sqlwhere = string.Format("WHERE t1.repair_yonghuid ='{0}' AND  t1.repair_status1 <> '0' ", repair_yonghuid);
                        //var list = mainsql.SqlExcuteWithReturn(string.Format("select * from {0}  t1 left join  {2} t2 on t1.repair_companyid=t2.user_id  {1} order by t1.repair_createtime desc;", BIAOUSERREPAIR, sqlwhere, BIAOUSERCOMPANY)).ToModels();

                        //ret.Maplist_MapArgs = new Dictionary<string, List<Dictionary<string, string>>>();
                        //ret.Maplist_MapArgs.Add("Data", list);

                        //if (list.Count > 0)
                        //{
                        //    var ids = string.Join(",", list.Where(x => !string.IsNullOrWhiteSpace(x["repair_repairpic_ids"])).Select(x => x["repair_repairpic_ids"])).Split(",".ToArray(), StringSplitOptions.RemoveEmptyEntries);

                        //    if (ids.Length > 0)
                        //    {
                        //        var files = mainsql.SqlExcuteWithReturn($"select file_id,file_path from {BIAOSHOPFILE} where file_id in('{string.Join("','", ids)}')   ").ToModels();
                        //        ret.Maplist_MapArgs.Add("Files", files);
                        //    }

                        //    ids = string.Join(",", list.Where(x => !string.IsNullOrWhiteSpace(x["repair_carpic"])).Select(x => x["repair_carpic"])).Split(",".ToArray(), StringSplitOptions.RemoveEmptyEntries);

                        //    if (ids.Length > 0)
                        //    {
                        //        var files = mainsql.SqlExcuteWithReturn($"select file_id,file_path from {BIAOSHOPFILE} where file_id in('{string.Join("','", ids)}')").ToModels();
                        //        ret.Maplist_MapArgs.Add("CarFiles", files);
                        //    }
                        //}
                        break;

                    case "2":
                        if (!string.IsNullOrWhiteSpace(companyId))
                        {
                            GetOrderAll(mainsql, ret.Maplist_MapArgs, companyId, pageIndex, pageSize);
                        }

                        //var pageIndex = comrcv.Map_Args["pageIndex"].ToInt32();
                        //pageIndex = pageIndex == 0 ? 1 : pageIndex;
                        //var pageSize = comrcv.Map_Args["pageSize"].ToInt32();
                        //pageSize = pageSize == 0 ? 10 : pageSize;

                        //var companyid = comrcv.Map_Args["companyid"];
                        //if (string.IsNullOrWhiteSpace(companyid))
                        //{
                        //    ret.Map_Args["ErrorMsg"] = "参数异常";
                        //    mainsql.closesql();
                        //    goto EXIT;
                        //}

                        //StringBuilder sql = new StringBuilder();
                        //sql.AppendFormat("select t1.*,t2.shop_name as ShopName,t3.file_small_path as ShopTitlePath,t4.sa_status from {0} t1 "
                        //    + "left join {1} t2 on t1.shop_id=t2.shop_id "
                        //    + "left join {2} t3 on t2.shop_title_id=t3.file_id "
                        //    + $"inner join {BIAOUSER} u on t1.order_to_user_id=u.user_onlyid and u.companyid='{companyid}' "
                        //    + "left join (select order_id,0 as sa_status from {3} where sa_status<>1 group by order_id) t4 on t1.order_id=t4.order_id where t1.order_deleteflag=0", BIAOORDER, BIAOSHOP, BIAOSHOPFILE, BIAOORDERSALE);

                        //string sqlStr = $"select t1.*,t3.file_small_path as ProductTitlePath from {BIAOORDERPRODUCT} t1 left join ({sql.ToString()}) t2 on t1.order_id=t2.order_id left join {BIAOSHOPFILE} t3 on t1.order_prd_cover_id=t3.file_id where t2.order_id>0";
                        //sql.AppendFormat(" order by t1.order_create_time desc limit {0},{1}", pageSize * pageIndex - pageSize, pageSize);

                        //var models = mainsql.SqlExcuteWithReturn(sql.ToString()).ToModels();

                        //if (models.Count > 0)
                        //{
                        //    ret.Maplist_MapArgs.Add("Products", mainsql.SqlExcuteWithReturn(sqlStr).ToModels());
                        //}

                        //ret.Maplist_MapArgs.Add("Data", models);

                        break;

                    case "3":
                        GetCommtityOrderAll(mainsql, ret.Maplist_MapArgs, userId, pageIndex, pageSize);
                        //var sqlCom = $@"select d.user_name,d.user_phone,c.user_companyname,b.commodity_name,b.commodity_file_id, a.* from s_commoditybuyorder a 
                        //left join s_commodity b on a.commodity_id=b.commodity_id
                        //left join s_usercompany c on a.company_id=c.user_id
                        //left join yonghualluser d on a.user_id=d.user_onlyid where a.user_id='{userId}' order by buy_order_create_time desc";
                        //var commpditytypes = mainsql.SqlExcuteWithReturn(sqlCom).ToModels();

                        //commpditytypes.ForEach(t =>
                        //{
                        //    //编辑状态
                        //    if ((t["buy_order_pay_status"].Equals("1") || t["buy_order_pay_status"].Equals("6")) && t["buy_order_status"].Equals("0"))
                        //    {
                        //        t["orderStatus"] = "未核销";
                        //    }
                        //    else if ((t["buy_order_pay_status"].Equals("1") || t["buy_order_pay_status"].Equals("6")) && t["buy_order_status"].Equals("1"))
                        //    {
                        //        t["orderStatus"] = "已核销";
                        //    }
                        //    else if (t["buy_order_status"].Equals("2"))
                        //    {
                        //        t["orderStatus"] = "订单已取消";
                        //    }
                        //    else if (t["buy_order_pay_status"].Equals("2"))
                        //    {
                        //        t["orderStatus"] = "申请退款";
                        //    }
                        //    else if (t["buy_order_pay_status"].Equals("3"))
                        //    {
                        //        t["orderStatus"] = "等待退款";
                        //    }
                        //    else if (t["buy_order_pay_status"].Equals("4"))
                        //    {
                        //        t["orderStatus"] = "已退款";
                        //    }
                        //    else if (t["buy_order_pay_status"].Equals("5"))
                        //    {
                        //        t["orderStatus"] = "支付失败";
                        //    }
                        //    else
                        //    {
                        //        t["orderStatus"] = "未支付";
                        //    }

                        //    //获取图片
                        //    t["file_small_path"] = "";

                        //    if (!string.IsNullOrWhiteSpace(t["commodity_file_id"]))
                        //    {
                        //        var ids = t["commodity_file_id"].Split(',');

                        //        if (ids.Length > 0)
                        //        {
                        //            t["file_small_path"] = mainsql.SqlExecuteScalar($"select file_path from s_files where file_id='{ids[0]}' limit 0,1").ToString();
                        //        }
                        //    }
                        //});

                        //ret.Maplist_MapArgs = new Dictionary<string, List<Dictionary<string, string>>>();
                        //ret.Maplist_MapArgs.Add("Data", commpditytypes);
                        break;

                    default:
                        if (!string.IsNullOrWhiteSpace(userId))
                        {
                            GetCommtityOrderAll(mainsql, ret.Maplist_MapArgs, userId, pageIndex, pageSize);
                            GetRepairOrderAll(mainsql, ret.Maplist_MapArgs, userId, pageIndex, pageSize);
                        }
                        if (!string.IsNullOrWhiteSpace(companyId))
                        {
                            GetOrderAll(mainsql, ret.Maplist_MapArgs, companyId, pageIndex, pageSize);
                        }
                        break;
                }

                ret.Byte_Flag = (sbyte)1;
                ret.Map_Args["ErrorMsg"] = "操作成功";
            }
            catch (Exception ex)
            {
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                loginfo.Info(ex);
            }

            mainsql.closesql();
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }

        /// <summary>
        /// 维修订单
        /// </summary>
        /// <param name="mainsql"></param>
        /// <param name="repair_yonghuid"></param>
        /// <returns></returns>
        public void GetRepairOrderAll(mysqlcli mainsql, Dictionary<string, List<Dictionary<string, string>>> dics, string repair_yonghuid, int pageIndex, int pageSize)
        {
            string couponbiao = "s_coupon";
            var sqlwhere = string.Format("WHERE t1.repair_yonghuid ='{0}' AND  t1.repair_status1 <> '0' ", repair_yonghuid);
            var list = mainsql.SqlExcuteWithReturn($@"
                                                    select  'repair' as orderType,t1.repair_createtime as orderCreateTime,t2.*,t1.*,t3.* 
                                                    from {BIAOUSERREPAIR}  t1 
                                                    left join  {BIAOUSERCOMPANY} t2 on t1.repair_companyid=t2.user_id 
                                                    left join  {couponbiao} t3 on t1.repair_couponid=t3.Sid {sqlwhere} 
                                                    order by t1.repair_createtime desc limit {pageSize * pageIndex - pageSize},{pageSize};").ToModels();
            dics.Add("repairData", list);

            if (list.Count > 0)
            {
                var ids = string.Join(",", list.Where(x => !string.IsNullOrWhiteSpace(x["repair_repairpic_ids"])).Select(x => x["repair_repairpic_ids"])).Split(",".ToArray(), StringSplitOptions.RemoveEmptyEntries);

                if (ids.Length > 0)
                {
                    var files = mainsql.SqlExcuteWithReturn($"select file_id,file_path from {BIAOSHOPFILE} where file_id in('{string.Join("','", ids)}')   ").ToModels();
                    dics.Add("Files", files);
                }

                ids = string.Join(",", list.Where(x => !string.IsNullOrWhiteSpace(x["repair_carpic"])).Select(x => x["repair_carpic"])).Split(",".ToArray(), StringSplitOptions.RemoveEmptyEntries);

                if (ids.Length > 0)
                {
                    var files = mainsql.SqlExcuteWithReturn($"select file_id,file_path from {BIAOSHOPFILE} where file_id in('{string.Join("','", ids)}')").ToModels();
                    dics.Add("CarFiles", files);
                }
            }
        }

        /// <summary>
        /// 商品订单
        /// </summary>
        /// <param name="mainsql"></param>
        /// <param name="companyid"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public void GetOrderAll(mysqlcli mainsql, Dictionary<string, List<Dictionary<string, string>>> dics, string companyid, int pageIndex, int pageSize)
        {
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat("select  'goods' as orderType,t1.order_create_time as orderCreateTime,t1.*,t2.shop_name as ShopName,t3.file_small_path as ShopTitlePath,t4.sa_status from {0} t1 "
                + "left join {1} t2 on t1.shop_id=t2.shop_id "
                + "left join {2} t3 on t2.shop_title_id=t3.file_id "
                + $"inner join {BIAOUSER} u on t1.order_to_user_id=u.user_onlyid and u.companyid='{companyid}' "
                + "left join (select order_id,0 as sa_status from {3} where sa_status<>1 group by order_id) t4 on t1.order_id=t4.order_id where t1.order_deleteflag=0", BIAOORDER, BIAOSHOP, BIAOSHOPFILE, BIAOORDERSALE);

            string sqlStr = $"select t1.*,t3.file_small_path as ProductTitlePath from {BIAOORDERPRODUCT} t1 left join ({sql.ToString()}) t2 on t1.order_id=t2.order_id left join {BIAOSHOPFILE} t3 on t1.order_prd_cover_id=t3.file_id where t2.order_id>0";
            sql.AppendFormat(" order by t1.order_create_time desc limit {0},{1}", pageSize * pageIndex - pageSize, pageSize);

            var models = mainsql.SqlExcuteWithReturn(sql.ToString()).ToModels();

            if (models.Count > 0)
            {
                dics.Add("Products", mainsql.SqlExcuteWithReturn(sqlStr).ToModels());
            }

            dics.Add("goodsData", models);
        }

        /// <summary>
        /// 团购订单
        /// </summary>
        /// <param name="mainsql"></param>
        /// <param name="userId"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public void GetCommtityOrderAll(mysqlcli mainsql, Dictionary<string, List<Dictionary<string, string>>> dics, string userId, int pageIndex, int pageSize)
        {
            var sqlCom = $@"select 'store' as orderType,a.buy_order_create_time as orderCreateTime, d.user_name,d.user_phone,c.user_companyname,b.commodity_name,b.commodity_file_id, a.* from s_commoditybuyorder a 
                        left join s_commodity b on a.commodity_id=b.commodity_id
                        left join s_usercompany c on a.company_id=c.user_id
                        left join yonghualluser d on a.user_id=d.user_onlyid where a.user_id='{userId}' order by buy_order_create_time desc limit {pageSize * pageIndex - pageSize},{pageSize}";
            var commpditytypes = mainsql.SqlExcuteWithReturn(sqlCom).ToModels();

            commpditytypes.ForEach(t =>
            {
                //编辑状态
                if ((t["buy_order_pay_status"].Equals("1") || t["buy_order_pay_status"].Equals("6")) && t["buy_order_status"].Equals("0"))
                {
                    t["orderStatus"] = "未核销";
                }
                else if ((t["buy_order_pay_status"].Equals("1") || t["buy_order_pay_status"].Equals("6")) && t["buy_order_status"].Equals("1"))
                {
                    t["orderStatus"] = "已核销";
                }
                else if (t["buy_order_status"].Equals("2"))
                {
                    t["orderStatus"] = "订单已取消";
                }
                else if (t["buy_order_pay_status"].Equals("2"))
                {
                    t["orderStatus"] = "申请退款";
                }
                else if (t["buy_order_pay_status"].Equals("3"))
                {
                    t["orderStatus"] = "等待退款";
                }
                else if (t["buy_order_pay_status"].Equals("4"))
                {
                    t["orderStatus"] = "已退款";
                }
                else if (t["buy_order_pay_status"].Equals("5"))
                {
                    t["orderStatus"] = "支付失败";
                }
                else
                {
                    t["orderStatus"] = "未支付";
                }

                //获取图片
                t["file_small_path"] = "";

                if (!string.IsNullOrWhiteSpace(t["commodity_file_id"]))
                {
                    var ids = t["commodity_file_id"].Split(',');

                    if (ids.Length > 0)
                    {
                        t["file_small_path"] = mainsql.SqlExecuteScalar($"select file_path from s_files where file_id='{ids[0]}' limit 0,1")?.ToString();
                    }
                }
            });

            dics.Add("storeData", commpditytypes);
        }

        [WebMethod(Description = "用户查询自己的维修单")]
        public string YongHu_GetRepairList(string msg)
        {
            ILog loginfo = LogManager.GetLogger("LoggerJieKou");

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);

            mysqlcli mainsql = new mysqlcli();

            mainsql.openShopServicesql();

            try
            {
                string repair_yonghuid = comrcv.Map_Args["yonghuid"];//用户的id

                string sqlwhere = string.Format("WHERE t1.repair_yonghuid ='{0}' AND  t1.repair_status1 <> '0' ", repair_yonghuid);


                var ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0}  t1 " +
                    " left join  {2} t2 on t1.repair_companyid=t2.user_id " +
                    " left join  {3} t3 on t1.repair_couponid=t3.Sid " +
                    " {1} order by t1.repair_createtime desc;", BIAOUSERREPAIR, sqlwhere, BIAOUSERCOMPANY, "s_coupon"));

                ret.Maplist_MapArgs = new Dictionary<string, List<Dictionary<string, string>>>();
                var lis = ds.ToModels();

                ret.Maplist_MapArgs.Add("Datas", lis);

                if (lis.Count > 0)
                {
                    var ids = string.Join(",", lis.Where(x => !string.IsNullOrWhiteSpace(x["repair_repairpic_ids"])).Select(x => x["repair_repairpic_ids"])).Split(",".ToArray(), StringSplitOptions.RemoveEmptyEntries);
                    if (ids.Length > 0)
                    {
                        var files = mainsql.SqlExcuteWithReturn($"select file_id,file_path from {BIAOSHOPFILE} where file_id in('{string.Join("','", ids)}')   ").ToModels();
                        ret.Maplist_MapArgs.Add("Files", files);
                    }
                    ids = string.Join(",", lis.Where(x => !string.IsNullOrWhiteSpace(x["repair_carpic"])).Select(x => x["repair_carpic"])).Split(",".ToArray(), StringSplitOptions.RemoveEmptyEntries);
                    if (ids.Length > 0)
                    {
                        var files = mainsql.SqlExcuteWithReturn($"select file_id,file_path from {BIAOSHOPFILE} where file_id in('{string.Join("','", ids)}')").ToModels();
                        ret.Maplist_MapArgs.Add("CarFiles", files);
                    }

                }



                mainsql.closesql();

                ret.Byte_Flag = (sbyte)1;

            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                loginfo.Info(ex);
            }

        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }

        [WebMethod(Description = "修理厂查询自己的维修单")]
        public string Company_GetRepairList(string msg)
        {
            ILog loginfo = LogManager.GetLogger("LoggerJieKou");

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);

            mysqlcli mainsql = new mysqlcli();

            mainsql.openShopServicesql();

            try
            {
                string repair_companyid = comrcv.Map_Args["companyid"];//用户的id
                using (TransactionScope tsall = new TransactionScope())
                {
                    string sqlwhere = string.Format("WHERE repair_companyid ='{0}'  AND  repair_status1 <> '0'  ", repair_companyid);


                    var ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} {1} order by repair_createtime desc;", BIAOUSERREPAIR, sqlwhere));

                    ret.Maplist_MapArgs = new Dictionary<string, List<Dictionary<string, string>>>();
                    var lis = ds.ToModels();

                    ret.Maplist_MapArgs.Add("Datas", lis);

                    if (lis.Count > 0)
                    {
                        var ids = string.Join(",", lis.Where(x => !string.IsNullOrWhiteSpace(x["repair_repairpic_ids"])).Select(x => x["repair_repairpic_ids"])).Split(",".ToArray(), StringSplitOptions.RemoveEmptyEntries);
                        if (ids.Length > 0)
                        {
                            var files = mainsql.SqlExcuteWithReturn($"select file_id,file_path from {BIAOSHOPFILE} where file_id in('{string.Join("','", ids)}')").ToModels();
                            ret.Maplist_MapArgs.Add("Files", files);
                        }
                        ids = string.Join(",", lis.Where(x => !string.IsNullOrWhiteSpace(x["repair_carpic"])).Select(x => x["repair_carpic"])).Split(",".ToArray(), StringSplitOptions.RemoveEmptyEntries);
                        if (ids.Length > 0)
                        {
                            var files = mainsql.SqlExcuteWithReturn($"select file_id,file_path from {BIAOSHOPFILE} where file_id in('{string.Join("','", ids)}')").ToModels();
                            ret.Maplist_MapArgs.Add("CarFiles", files);
                        }
                    }

                    mainsql.closesql();
                    tsall.Complete();
                    ret.Byte_Flag = (sbyte)1;
                }
            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                loginfo.Info(ex);
            }

        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }

        [WebMethod(Description = "商户查询自己的维修单")]
        public string ShangHu_GetRepairList(string msg)
        {
            ILog loginfo = LogManager.GetLogger("LoggerJieKou");

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);

            mysqlcli mainsql = new mysqlcli();

            mainsql.openShopServicesql();

            try
            {
                string repair_shopid = comrcv.Map_Args["repair_shopid"];//用户的id
                string orderState = comrcv.Map_Args["orderState"];//订单的orderState

                //string repair_shopid = "";
                //string orderState = "";

                using (TransactionScope tsall = new TransactionScope())
                {
                    string sqlwhere = string.Format("WHERE repair_shopid like '%{0}%' ", repair_shopid);

                    switch (orderState)
                    {
                        case "0": break;
                        case "1":
                            sqlwhere += " AND repair_status1<>6";
                            break;
                        case "2":
                            sqlwhere += " AND repair_status1=6";
                            break;
                    }


                    var ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} {1} order by repair_createtime desc;", BIAOUSERREPAIR, sqlwhere));

                    ret.Maplist_MapArgs = new Dictionary<string, List<Dictionary<string, string>>>();
                    var lis = ds.ToModels();

                    ret.Maplist_MapArgs.Add("Datas", lis);

                    if (lis.Count > 0)
                    {
                        var ids = string.Join(",", lis.Where(x => !string.IsNullOrWhiteSpace(x["repair_repairpic_ids"])).Select(x => x["repair_repairpic_ids"])).Split(",".ToArray(), StringSplitOptions.RemoveEmptyEntries);
                        if (ids.Length > 0)
                        {
                            var files = mainsql.SqlExcuteWithReturn($"select file_id,file_path from {BIAOSHOPFILE} where file_id in('{string.Join("','", ids)}')").ToModels();
                            ret.Maplist_MapArgs.Add("Files", files);
                        }
                        ids = string.Join(",", lis.Where(x => !string.IsNullOrWhiteSpace(x["repair_carpic"])).Select(x => x["repair_carpic"])).Split(",".ToArray(), StringSplitOptions.RemoveEmptyEntries);
                        if (ids.Length > 0)
                        {
                            var files = mainsql.SqlExcuteWithReturn($"select file_id,file_path from {BIAOSHOPFILE} where file_id in('{string.Join("','", ids)}')").ToModels();
                            ret.Maplist_MapArgs.Add("CarFiles", files);
                        }

                    }

                    mainsql.closesql();
                    tsall.Complete();
                    ret.Byte_Flag = (sbyte)1;
                }
            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                loginfo.Info(ex);
            }

        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }

        [WebMethod(Description = "根据id返回维修单详情")]
        public string All_GetRepairInfo(string msg)
        {
            ILog loginfo = LogManager.GetLogger("LoggerJieKou");

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);

            mysqlcli mainsql = new mysqlcli();

            mainsql.openShopServicesql();

            try
            {
                var repair_id = comrcv.Map_Args["repair_id"];
                var ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} WHERE repair_id ='{1}' ;", BIAOUSERREPAIR, repair_id));
                if (ds.Rows.Count == 0)
                {
                    mainsql.closesql();
                    ret.Map_Args["ErrorMsg"] = "没有相关订单";
                    goto EXIT;
                }
                string repair_companyid = ds.Rows[0]["repair_companyid"].ToString();

                ret.Maplist_MapArgs = new Dictionary<string, List<Dictionary<string, string>>>();
                ret.Maplist_MapArgs.Add("datas", ds.ToModels());

                var lis = ds.ToModels();

                if (lis.Count > 0)
                {
                    var ids = string.Join(",", lis.Where(x => !string.IsNullOrWhiteSpace(x["repair_repairpic_ids"])).Select(x => x["repair_repairpic_ids"])).Split(",".ToArray(), StringSplitOptions.RemoveEmptyEntries);
                    if (ids.Length > 0)
                    {
                        var files = mainsql.SqlExcuteWithReturn($"select file_id,file_path from {BIAOSHOPFILE} where file_id in('{string.Join("','", ids)}')").ToModels();
                        ret.Maplist_MapArgs.Add("Files", files);
                    }

                    ids = string.Join(",", lis.Where(x => !string.IsNullOrWhiteSpace(x["repair_carpic"])).Select(x => x["repair_carpic"])).Split(",".ToArray(), StringSplitOptions.RemoveEmptyEntries);
                    if (ids.Length > 0)
                    {
                        var files = mainsql.SqlExcuteWithReturn($"select file_id,file_path from {BIAOSHOPFILE} where file_id in('{string.Join("','", ids)}')").ToModels();
                        ret.Maplist_MapArgs.Add("CarFiles", files);
                    }

                }
                ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} WHERE user_id='{1}'", BIAOUSERCOMPANY, repair_companyid));
                ret.Maplist_MapArgs.Add("companydatas", ds.ToModels());
                var companyfiles = mainsql.SqlExcuteWithReturn($"select file_id,file_path from {BIAOSHOPFILE} where file_id ='{ds.Rows[0]["user_mentou"].ToString()}'").ToModels();
                ret.Maplist_MapArgs.Add("companyfiles", companyfiles);

                mainsql.closesql();

                ret.Byte_Flag = (sbyte)1;

            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                loginfo.Info(ex);
            }

        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }

        #endregion

        #region 支付相关接口
        //请求传化支付商品订单费用
        [WebMethod(Description = "用户确认支付")]//0-0-0
        public string Yonghu_SureRepairZhifu(string msg)
        {
            ILog logJieKou = LogManager.GetLogger("LoggerZhiFu");
            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv);
            mysqlcli mainsql = new mysqlcli();
            string qgliushuinumber = "";
            try
            {
                logJieKou.Info("请求传化支付商品订单费用开始请求-");
                string shop_id = "";                                  //商户基本id
                string openid = comrcv.Map_Args["openid"];              //当前支付人的OPENID
                string jine = comrcv.Map_Args["cost"];                  //金额

                double doublejine = 0;
                double.TryParse(jine, out doublejine);
                string repair_id = comrcv.Map_Args["repair_id"];            //维修单号

                string user_phone = "";             //买家人电话
                string user_name = "";        //买家人姓名
                string user_id = "";        //买家人唯一编码
                string chbusinessrecordnumber = "";
                string companynumber = "";
                string shop_name = "老顶坡汽摩平台";


                string oldcost = jine;//原金额


                using (TransactionScope tsall = new TransactionScope())
                {

                    mainsql.openYongHuServicesql();

                    string sqlcmd = string.Format("select * from {0} WHERE repair_id ='{1}' ;", BIAOUSERREPAIR, repair_id);
                    var ds = mainsql.SqlExcuteWithReturn(sqlcmd);
                    if (ds.Rows.Count == 0)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "没有相关订单";
                        goto EXIT;
                    }
                    user_id = ds.Rows[0]["repair_yonghuid"].ToString();
                    user_name = ds.Rows[0]["repair_yonghuname"].ToString();
                    user_phone = ds.Rows[0]["repair_yonghuphone"].ToString();

                    qgliushuinumber = GetLdpLiushui(mainsql);
                    string status = "等待支付";

                    if (doublejine > 0)
                    {

                        #region 调用传化接口

                        string subjectstring = shop_name + "-商品支付";
                        string logip = "";
                        try
                        {
                            logip = Context.Request.ServerVariables.Get("Remote_Addr").ToString();
                        }
                        catch
                        { }

                        Dictionary<string, string> zfmapargs = new Dictionary<string, string>();
                        zfmapargs.Add("subjectstring", subjectstring);
                        zfmapargs.Add("logip", logip);
                        zfmapargs.Add("companyname", shop_name);
                        zfmapargs.Add("qgliushuinumber", qgliushuinumber);
                        zfmapargs.Add("jine", jine);
                        zfmapargs.Add("openid", openid);
                        zfmapargs.Add("ErrorMsg", "无错误");

                        if (CH_ZHIFU_COMMON(ref zfmapargs) == true)
                        {
                            ret.Map_Args["appId"] = zfmapargs["appId"];
                            ret.Map_Args["timeStamp"] = zfmapargs["timeStamp"];
                            ret.Map_Args["nonceStr"] = zfmapargs["nonceStr"];
                            ret.Map_Args["package"] = zfmapargs["package"];
                            ret.Map_Args["signType"] = zfmapargs["signType"];
                            ret.Map_Args["paySign"] = zfmapargs["paySign"];
                            ret.Map_Args["qgliushuinumber"] = qgliushuinumber;
                            chbusinessrecordnumber = zfmapargs["chbusinessrecordnumber"];
                        }
                        else
                        {
                            ret.Map_Args["ErrorMsg"] = zfmapargs["ErrorMsg"];   //参数错误
                            goto EXIT;
                        }
                        #endregion
                    }
                    else
                    {
                        status = "支付成功";

                        string updatestr = string.Format(" repair_status1='3',repair_status2='5' ,repair_status3='{0}' ", 1);
                        string cmd = string.Format(" update {0} set {1} where repair_id ='{2}' ;", BIAOUSERREPAIR, updatestr, repair_id);
                        int retint = mainsql.SqlExcuteNoReturn(cmd);
                        if (retint != 1)
                        {
                            mainsql.closesql();
                            throw new Exception("用户更改状态失败");
                        }
                    }
                    string defaultstr = string.Format("用户支付{0}元", oldcost);


                    //是否存在优惠券
                    if (comrcv.Map_Args.Keys.Contains("coupon_id") && !string.IsNullOrWhiteSpace(comrcv.Map_Args["coupon_id"]))
                    {
                        string updatestr = string.Format(" repair_couponid='{0}' ", comrcv.Map_Args["coupon_id"]);
                        string cmd = string.Format(" update {0} set {1} where repair_id ='{2}' ;", BIAOUSERREPAIR, updatestr, repair_id);
                        int retint = mainsql.SqlExcuteNoReturn(cmd);
                        if (retint != 1)
                        {
                            mainsql.closesql();
                            throw new Exception("用户更改状态失败");
                        }
                        ////更改优惠券状态
                        //var sql = $"update s_coupon set coupon_status=1,coupon_updateime=NOW() where Sid='{comrcv.Map_Args["coupon_id"]}';";
                        //mainsql.SqlExcuteNoReturn(sql);
                        if (comrcv.Map_Args.Keys.Contains("oldcost") && !string.IsNullOrWhiteSpace(comrcv.Map_Args["oldcost"]))
                        {
                            defaultstr = string.Format("用户使用优惠券支付{0}元,原金额{1}元", oldcost, comrcv.Map_Args["oldcost"]);
                        }
                    }

                    #region 生成账单记录表



                    sqlcmd = string.Format("INSERT INTO {0} (zf_time,zf_type,zf_status,zf_qgnumber,zf_chnumber,zf_biaoid,zf_companyaccount," +
                        "zf_companynumber,zf_companyname,zf_yhamount,zf_yholdamount,zf_qgamount,zf_companyamount,zf_default,zf_zfphone,zf_way,zf_shouzhi,zf_comshouzhi,zf_zfonlyid)" +
                        " VALUES ('{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}','微信','2','1','{16}')",
                        BIAOQGZHIFURECORD + DateTime.Now.ToString("yyyyMM"), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "维修支付", status, qgliushuinumber,
                        chbusinessrecordnumber, repair_id, shop_id, companynumber, shop_name,
                        oldcost, oldcost, 0.ToString("0.00"), oldcost, defaultstr, user_phone, user_id);
                    int sqlret = mainsql.SqlExcuteNoReturn(sqlcmd);
                    if (sqlret != 1)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "插入记录失败";  //参数错误
                        goto EXIT;
                    }
                    #endregion

                    ret.Byte_Flag = (sbyte)1;
                    mainsql.closesql();
                    tsall.Complete();
                }


            }
            catch (Exception ex)
            {
                logJieKou.Info("聚合支付异常-" + ex.Message);
                mainsql.closesql();
                goto EXIT;
            }

        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }

        //请求传化支付商品订单费用OK
        [WebMethod(Description = "用户确认支付OK")]//3-5-1
        public string Yonghu_SureRepairZhifuOK(string msg)
        {
            ILog logJieKou = LogManager.GetLogger("LoggerZhiFu");
            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv);

            try
            {
                logJieKou.Info("请求传化支付商品订单费用OK-");

                string repair_id = comrcv.Map_Args["repair_id"];
                string qgliushuinumber = comrcv.Map_Args["qgliushuinumber"];

                weixiu_huidiao(repair_id, qgliushuinumber, true);


                mysqlcli mainsql1 = new mysqlcli();
                mainsql1.openYongHuServicesql();
                var ds = mainsql1.SqlExcuteWithReturn(string.Format("select * from {0} WHERE repair_id ='{1}' ;", BIAOUSERREPAIR, repair_id));
                if (ds.Rows.Count == 0)
                {
                    mainsql1.closesql();
                    ret.Map_Args["ErrorMsg"] = "没有相关订单";
                    goto EXIT;
                }
                string repair_companyid = ds.Rows[0]["repair_companyid"].ToString();
                string repair_companyname = ds.Rows[0]["repair_companyname"].ToString();
                string repair_carplate = ds.Rows[0]["repair_carplate"].ToString();
                string repair_yonghuname = ds.Rows[0]["repair_yonghuname"].ToString();
                string repair_allprice = ds.Rows[0]["repair_allprice"].ToString();
                string repair_shopid = ds.Rows[0]["repair_shopid"].ToString();
                string repair_productprice = ds.Rows[0]["repair_productprice"].ToString();



                #region 给修理厂发微信消息
                {

                    var user_binduserid = mainsql1.SqlExecuteScalar($"select user_binduserid from {BIAOUSERCOMPANY} where user_id='{repair_companyid}'").ToString();
                    var ids = user_binduserid.Split(",".ToArray(), StringSplitOptions.RemoveEmptyEntries);
                    var user_onlyids = string.Join("','", ids);
                    var userModel = mainsql1.SqlExcuteWithReturn($"select user_openid_juhesheng from {BIAOUSER} where user_phone IN ('{user_onlyids}')  ").ToModels();


                    foreach (var uitem in userModel)
                    {
                        var openid = uitem["user_openid_juhesheng"];

                        if (!string.IsNullOrWhiteSpace(openid))
                        {
                            //发送消息
                            WebServiceShopping.wechartTools.SendMsgGZH(new WebServiceShopping.wechartTools.PayOKMsg()
                            {
                                miniprogram = new WebServiceShopping.wechartTools.XCXPath()
                                {
                                    pagepath = $"/pages/my/repairfactory/index/index?companyid={repair_companyid}"
                                },
                                touser = openid,
                                data = new WebServiceShopping.wechartTools.PayOKMsg.DataModel()
                                {
                                    first = new WebServiceShopping.wechartTools.DataItem()
                                    {
                                        value = $"您的客户已经付款！"
                                    },
                                    keyword1 = new WebServiceShopping.wechartTools.DataItem()
                                    {
                                        value = $"【{repair_yonghuname}】-({repair_carplate})"
                                    },
                                    keyword2 = new WebServiceShopping.wechartTools.DataItem()
                                    {
                                        value = repair_allprice + "元"
                                    },
                                    keyword3 = new WebServiceShopping.wechartTools.DataItem()
                                    {
                                        value = repair_companyname
                                    },
                                    keyword4 = new WebServiceShopping.wechartTools.DataItem()
                                    {
                                        value = DateTime.Now.ToString("yyyy年MM月dd HH:mm")
                                    },
                                    remark = new WebServiceShopping.wechartTools.DataItem()
                                    {
                                        value = $"您的客户已经付款，请跟进发货和维修！"
                                    },
                                }
                            });
                        }
                    }
                }




                #endregion

                #region 发商家微信消息

                if (repair_shopid != repair_companyid)
                {
                    var userIds = new List<string>();


                    var users = mainsql1.SqlExcuteWithReturn($"select t2.user_openid_juhesheng,t2.user_phone,t2.user_name,t2.user_onlyid from {BIAOSHOPUSER} t1 left join {BIAOUSER} t2 on t1.user_id=t2.user_onlyid where shop_id='{repair_shopid}' and shop_user_ismsg=1 and shop_user_deleteflag<>1").ToModels();
                    foreach (var uitem in users)
                    {
                        var openid = uitem["user_openid_juhesheng"];
                        if (!string.IsNullOrWhiteSpace(openid))
                        {
                            //发送消息
                            WebServiceShopping.wechartTools.SendMsgGZH(new WebServiceShopping.wechartTools.PayOKMsg()
                            {
                                miniprogram = new WebServiceShopping.wechartTools.XCXPath()
                                {
                                    pagepath = "/pages/my/store/store?ShopId=" + repair_shopid
                                },
                                touser = openid,
                                data = new WebServiceShopping.wechartTools.PayOKMsg.DataModel()
                                {
                                    first = new WebServiceShopping.wechartTools.DataItem()
                                    {
                                        value = $"您的客户已经付款！"
                                    },
                                    keyword1 = new WebServiceShopping.wechartTools.DataItem()
                                    {
                                        value = $"【{repair_yonghuname}】-({repair_carplate})"
                                    },
                                    keyword2 = new WebServiceShopping.wechartTools.DataItem()
                                    {
                                        value = repair_productprice + "元"
                                    },
                                    keyword3 = new WebServiceShopping.wechartTools.DataItem()
                                    {
                                        value = repair_companyname
                                    },
                                    keyword4 = new WebServiceShopping.wechartTools.DataItem()
                                    {
                                        value = DateTime.Now.ToString("yyyy年MM月dd HH:mm")
                                    },
                                    remark = new WebServiceShopping.wechartTools.DataItem()
                                    {
                                        value = $"请您及时安排发货！"
                                    },
                                }
                            });
                        }
                    }

                }

                #endregion

                mainsql1.closesql();
            }
            catch (Exception ex)
            {
                logJieKou.Info("聚合支付异常-" + ex.Message);
                goto EXIT;
            }
            ret.Byte_Flag = (sbyte)1;
        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }

        //请求传化支付商品订单费用Cancel
        [WebMethod(Description = "用户确认支付失败")]//退回到3-5-0
        public string Yonghu_SureRepairZhifuCancel(string msg)
        {
            ILog logJieKou = LogManager.GetLogger("LoggerZhiFu");
            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv);
            mysqlcli mainsql = new mysqlcli();

            try
            {
                logJieKou.Info("请求传化支付商品订单费用Cancel-");
                string repair_id = comrcv.Map_Args["repair_id"];
                string qgliushuinumber = comrcv.Map_Args["qgliushuinumber"];

                weixiu_huidiao(repair_id, qgliushuinumber, false);

            }
            catch (Exception ex)
            {
                logJieKou.Info("聚合支付异常-" + ex.Message);

                goto EXIT;
            }
            ret.Byte_Flag = (sbyte)1;
        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }

        //用户确认门店商品支付
        [WebMethod(Description = "用户确认门店商品支付")]
        public string Yonghu_StorePayment(string msg)
        {
            ILog logJieKou = LogManager.GetLogger("LoggerZhiFu");
            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv);
            mysqlcli mainsql = new mysqlcli();
            string qgliushuinumber = "";
            try
            {
                logJieKou.Info("请求传化支付商品订单费用开始请求-");
                string openid = comrcv.Map_Args["openid"];              //当前支付人的OPENID
                string jine = comrcv.Map_Args["cost"];                  //金额
                string userId = comrcv.Map_Args["userId"];              //用户onlyId
                string commodityId = comrcv.Map_Args["commodityId"];    //商品ID
                string buyOrderId = comrcv.Map_Args["buyOrderId"];       //订单ID
                string shop_name = "老顶坡汽摩平台";
                string company_id = "";                                 //商户基本id
                string chbusinessrecordnumber = "";
                string companynumber = "";
                string oldcost = jine;                                  //原金额
                string user_phone = "";                                 //买家人电话
                string user_name = "";                                  //买家人姓名
                string user_id = "";                                    //买家人唯一编码
                double doublejine = 0;
                double.TryParse(jine, out doublejine);
                using (TransactionScope tsall = new TransactionScope())
                {
                    mainsql.openYongHuServicesql();

                    //用户是否存在
                    var sql = $"select * from yonghualluser where user_onlyid='{userId}'";
                    var ds = mainsql.SqlExcuteWithReturn(sql);
                    if (ds.Rows.Count == 0)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "用户不存在";
                        goto EXIT;
                    };

                    user_id = userId;
                    user_name = ds.Rows[0]["user_name"].ToString();
                    user_phone = ds.Rows[0]["user_phone"].ToString();

                    //商品是否下架
                    sql = $"select * from s_commodity where commodity_status=1 and commodity_id='{commodityId}'";
                    ds = mainsql.SqlExcuteWithReturn(sql);
                    if (ds.Rows.Count == 0)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "商品已下架";
                        goto EXIT;
                    };

                    company_id = ds.Rows[0]["company_id"].ToString();

                    //修理厂是否存在
                    sql = $"select* from s_usercompany where user_id ='{company_id}'";
                    ds = mainsql.SqlExcuteWithReturn(sql);
                    if (ds.Rows.Count == 0)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "修理厂不存在";

                        goto EXIT;
                    };

                    var shopName = ds.Rows[0]["user_companyname"].ToString();

                    //是否存在订单
                    sql = $@"select * from s_commoditybuyorder where buy_order_id='{buyOrderId}'";
                    ds = mainsql.SqlExcuteWithReturn(sql);
                    if (ds.Rows.Count == 0)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "未查询到订单";
                        goto EXIT;
                    }

                    //是否存在优惠券 --验证优惠券是否使用
                    if (!string.IsNullOrWhiteSpace(ds.Rows[0]["buy_order_yhq"].ToString()))
                    {
                        sql = $@"select * from s_coupon where coupon_status=0 and Sid='{ds.Rows[0]["buy_order_yhq"]}';";
                        var couponDs = mainsql.SqlExcuteWithReturn(sql).ToModels().FirstOrDefault();
                        if (couponDs != null)
                        {
                            //修改订单未支付订单状态
                            sql = $"update s_commoditybuyorder set buy_order_yhq='',buy_order_pay_price=0,buy_order_pay_time=NOW() where user_id='{user_id}' and buy_order_id<>'{buyOrderId}' and buy_order_yhq='{ds.Rows[0]["buy_order_yhq"]}';";

                            mainsql.SqlExcuteNoReturn(sql);
                        }
                    }


                    //金额为0不走传化接口
                    if (doublejine > 0)
                    {
                        #region 调用传化接口
                        doublejine = Math.Round(doublejine, 2);

                        qgliushuinumber = GetLdpLiushui(mainsql);
                        string subjectstring = shop_name + "-商品支付";
                        string logip = "";
                        try
                        {
                            logip = Context.Request.ServerVariables.Get("Remote_Addr").ToString();
                        }
                        catch
                        { }

                        Dictionary<string, string> zfmapargs = new Dictionary<string, string>();
                        zfmapargs.Add("subjectstring", subjectstring);
                        zfmapargs.Add("logip", logip);
                        zfmapargs.Add("companyname", shop_name);
                        zfmapargs.Add("qgliushuinumber", qgliushuinumber);
                        zfmapargs.Add("jine", doublejine.ToString());
                        zfmapargs.Add("openid", openid);
                        zfmapargs.Add("ErrorMsg", "无错误");

                        if (CH_ZHIFU_COMMON(ref zfmapargs) == true)
                        {
                            ret.Map_Args["appId"] = zfmapargs["appId"];
                            ret.Map_Args["timeStamp"] = zfmapargs["timeStamp"];
                            ret.Map_Args["nonceStr"] = zfmapargs["nonceStr"];
                            ret.Map_Args["package"] = zfmapargs["package"];
                            ret.Map_Args["signType"] = zfmapargs["signType"];
                            ret.Map_Args["paySign"] = zfmapargs["paySign"];
                            ret.Map_Args["qgliushuinumber"] = qgliushuinumber;
                            chbusinessrecordnumber = zfmapargs["chbusinessrecordnumber"];
                        }
                        else
                        {
                            ret.Map_Args["ErrorMsg"] = zfmapargs["ErrorMsg"];   //参数错误
                            goto EXIT;
                        }
                        #endregion

                        #region 生成账单记录表

                        var price = ds.Rows[0]["buy_order_price"].ToString();//订单金额
                        var payPrice = ds.Rows[0]["buy_order_pay_price"].ToString();//订单金额
                        string defaultstr = string.Format("用户支付{0}元", doublejine);

                        sql = string.Format("INSERT INTO {0} (zf_time,zf_type,zf_status,zf_qgnumber,zf_chnumber,zf_biaoid,zf_companyaccount," +
                            "zf_companynumber,zf_companyname,zf_yhamount,zf_yholdamount,zf_qgamount,zf_companyamount,zf_default,zf_zfphone,zf_way,zf_shouzhi,zf_comshouzhi,zf_zfonlyid)" +
                            " VALUES ('{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}','微信','2','1','{16}')",
                            BIAOQGZHIFURECORD + DateTime.Now.ToString("yyyyMM"), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "团购支付", "等待支付", qgliushuinumber,
                            chbusinessrecordnumber, buyOrderId, company_id, companynumber, shopName,
                            price, price, 0.ToString("0.00"), price, defaultstr, user_phone, user_id);

                        int sqlret = mainsql.SqlExcuteNoReturn(sql);
                        if (sqlret != 1)
                        {
                            mainsql.closesql();
                            ret.Map_Args["ErrorMsg"] = "插入记录失败";  //参数错误
                            goto EXIT;
                        }

                        #endregion
                    };

                    ret.Byte_Flag = (sbyte)1;
                    tsall.Complete();
                    mainsql.closesql();
                }


            }
            catch (Exception ex)
            {
                logJieKou.Info("聚合支付异常-" + ex.Message);
                mainsql.closesql();
                goto EXIT;
            }

        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }

        //多订单合并支付
        [WebMethod(Description = "多订单合并支付")]
        public string Yonghu_StorePaymentNew(string msg)
        {
            ILog logJieKou = LogManager.GetLogger("LoggerZhiFu");
            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv);
            mysqlcli mainsql = new mysqlcli();
            string qgliushuinumber = "";
            try
            {
                logJieKou.Info("请求传化支付商品订单费用开始请求-");
                string openid = comrcv.Map_Args["openid"];              //当前支付人的OPENID
                string jine = comrcv.Map_Args["cost"];                  //金额
                string userId = comrcv.Map_Args["userId"];              //用户onlyId
                string buyOrderIds = comrcv.Map_Args["buyOrderIds"];       //订单ID
                string shop_name = "老顶坡汽摩平台";
                string company_id = "";                                 //商户基本id
                string chbusinessrecordnumber = "";
                string companynumber = "";
                string oldcost = jine;                                  //原金额
                string user_phone = "";                                 //买家人电话
                string user_name = "";                                  //买家人姓名
                string user_id = "";                                    //买家人唯一编码
                double doublejine = 0;
                double.TryParse(jine, out doublejine);
                mainsql.openYongHuServicesql();
                using (MySqlTransaction tr = mainsql.Connection().BeginTransaction())
                {

                    //用户是否存在
                    var sql = $"select * from yonghualluser where user_onlyid='{userId}'";
                    var user = mainsql.SqlExcuteWithReturn(sql).ToModels().FirstOrDefault();

                    if (user == null)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "用户不存在";
                        goto EXIT;
                    };

                    user_id = userId;
                    user_name = user["user_name"].ToString();
                    user_phone = user["user_phone"].ToString();

                    //金额为0不走传化接口
                    if (doublejine > 0)
                    {
                        #region 调用传化接口
                        doublejine = Math.Round(doublejine, 2);

                        qgliushuinumber = GetLdpLiushui(mainsql);
                        string subjectstring = shop_name + "-商品支付";
                        string logip = "";
                        try
                        {
                            logip = Context.Request.ServerVariables.Get("Remote_Addr").ToString();
                        }
                        catch
                        {
                        }

                        Dictionary<string, string> zfmapargs = new Dictionary<string, string>();
                        zfmapargs.Add("subjectstring", subjectstring);
                        zfmapargs.Add("logip", logip);
                        zfmapargs.Add("companyname", shop_name);
                        zfmapargs.Add("qgliushuinumber", qgliushuinumber);
                        zfmapargs.Add("jine", doublejine.ToString());
                        zfmapargs.Add("openid", openid);
                        zfmapargs.Add("ErrorMsg", "无错误");

                        if (CH_ZHIFU_COMMON(ref zfmapargs) == true)
                        {
                            ret.Map_Args["appId"] = zfmapargs["appId"];
                            ret.Map_Args["timeStamp"] = zfmapargs["timeStamp"];
                            ret.Map_Args["nonceStr"] = zfmapargs["nonceStr"];
                            ret.Map_Args["package"] = zfmapargs["package"];
                            ret.Map_Args["signType"] = zfmapargs["signType"];
                            ret.Map_Args["paySign"] = zfmapargs["paySign"];
                            ret.Map_Args["qgliushuinumber"] = qgliushuinumber;
                            chbusinessrecordnumber = zfmapargs["chbusinessrecordnumber"];
                            logJieKou.Info(chbusinessrecordnumber);
                        }
                        else
                        {
                            ret.Map_Args["ErrorMsg"] = zfmapargs["ErrorMsg"];   //参数错误
                            goto EXIT;
                        }
                        #endregion
                    }

                    //查询订单
                    var orderIds = buyOrderIds.Trim(',').Split(',');

                    if (orderIds.Length > 0)
                    {
                        foreach (var orderId in orderIds)
                        {
                            //是否存在订单
                            sql = $@"select * from s_commoditybuyorder where buy_order_id='{orderId}'";
                            var order = mainsql.SqlExcuteWithReturn(sql).ToModels().FirstOrDefault();
                            if (order == null)
                            {
                                mainsql.closesql();
                                ret.Map_Args["ErrorMsg"] = "未查询到订单";
                                goto EXIT;
                            }

                            string commodityId = order["commodity_id"];    //商品ID

                            //商品是否下架
                            sql = $"select * from s_commodity where commodity_status=1 and commodity_id='{commodityId}'";
                            var commodity = mainsql.SqlExcuteWithReturn(sql).ToModels().FirstOrDefault();

                            if (commodity == null)
                            {
                                mainsql.closesql();
                                ret.Map_Args["ErrorMsg"] = "商品已下架";
                                goto EXIT;
                            };

                            company_id = commodity["company_id"].ToString();

                            //修理厂是否存在
                            sql = $"select* from s_usercompany where user_id ='{company_id}'";
                            var usercompany = mainsql.SqlExcuteWithReturn(sql).ToModels().FirstOrDefault();

                            if (usercompany == null)
                            {
                                mainsql.closesql();
                                ret.Map_Args["ErrorMsg"] = "修理厂不存在";

                                goto EXIT;
                            };

                            var shopName = usercompany["user_companyname"].ToString();
                            var price = order["buy_order_price"].ToString();//订单金额
                            var payPrice = order["buy_order_pay_price"].ToString();//订单金额
                            var logAprice = price;

                            //是否存在优惠券 --验证优惠券是否使用
                            if (!string.IsNullOrWhiteSpace(order["buy_order_yhq"].ToString()))
                            {
                                logAprice = payPrice;
                                sql = $@"select * from s_coupon where coupon_status=0 and Sid='{order["buy_order_yhq"]}';";
                                var couponDs = mainsql.SqlExcuteWithReturn(sql).ToModels().FirstOrDefault();

                                if (couponDs != null)
                                {
                                    //修改订单未支付订单状态
                                    sql = $"update s_commoditybuyorder set buy_order_yhq='',buy_order_pay_price=0,buy_order_pay_time=NOW() where user_id='{user_id}' and buy_order_id<>'{orderId}' and buy_order_yhq='{order["buy_order_yhq"]}';";

                                    mainsql.SqlExcuteNoReturn(sql, tr);
                                }
                            }

                            //金额为0不走传化接口
                            if (doublejine > 0)
                            {
                                #region 生成账单记录表

                                string defaultstr = string.Format("用户支付{0}元", logAprice);

                                sql = string.Format("INSERT INTO {0} (zf_time,zf_type,zf_status,zf_qgnumber,zf_chnumber,zf_biaoid,zf_companyaccount," +
                                    "zf_companynumber,zf_companyname,zf_yhamount,zf_yholdamount,zf_qgamount,zf_companyamount,zf_default,zf_zfphone,zf_way,zf_shouzhi,zf_comshouzhi,zf_zfonlyid)" +
                                    " VALUES ('{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}','微信','2','1','{16}')",
                                    BIAOQGZHIFURECORD + DateTime.Now.ToString("yyyyMM"), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "团购支付", "等待支付", qgliushuinumber,
                                    chbusinessrecordnumber, orderId, company_id, companynumber, shopName,
                                    price, price, 0.ToString("0.00"), price, defaultstr, user_phone, user_id);

                                int sqlret = mainsql.SqlExcuteNoReturn(sql, tr);
                                if (sqlret != 1)
                                {
                                    mainsql.closesql();
                                    ret.Map_Args["ErrorMsg"] = "插入记录失败";  //参数错误
                                    goto EXIT;
                                }

                                #endregion
                            };
                        }
                    }
                    else
                    {
                        ret.Map_Args["ErrorMsg"] = "订单参数错误";   //参数错误
                        goto EXIT;
                    }

                    ret.Byte_Flag = (sbyte)1;
                    tr.Commit();
                    mainsql.closesql();
                }


            }
            catch (Exception ex)
            {
                logJieKou.Info("聚合支付异常-" + ex.Message);
                mainsql.closesql();
                goto EXIT;
            }

        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }

        //用户确认门店商品支付OK
        [WebMethod(Description = "用户确认门店商品支付OK")]
        public string Yonghu_StorePaymenOK(string msg)
        {
            ILog logJieKou = LogManager.GetLogger("LoggerZhiFu");
            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv);

            try
            {
                logJieKou.Info("请求传化支付商品订单费用OK-");

                string orderId = comrcv.Map_Args["orderId"];
                string qgliushuinumber = comrcv.Map_Args["qgliushuinumber"];

                tuangou_huidiao(orderId, qgliushuinumber, true, logJieKou);

                var orderArr = orderId.Trim(',').Split(',');

                mysqlcli mainsql1 = new mysqlcli();
                mainsql1.openYongHuServicesql();


                for (int i = 0; i < orderArr.Length; i++)
                {
                    string sql = $@"select  d.user_name,d.user_phone,b.commodity_name,c.user_companyname ,a.*
                                from s_commoditybuyorder a 
                                left join s_commodity b on a.commodity_id=b.commodity_id
                                left join s_usercompany c on a.company_id=c.user_id
                                left join yonghualluser d on a.user_id=d.user_onlyid
                                where a.buy_order_id='{orderArr[i]}'";

                    var ds = mainsql1.SqlExcuteWithReturn(sql);
                    if (ds.Rows.Count == 0)
                    {
                        mainsql1.closesql();
                        ret.Map_Args["ErrorMsg"] = "没有相关订单";
                        goto EXIT;
                    }

                    string company_id = ds.Rows[0]["company_id"].ToString();
                    string buy_order_price = ds.Rows[0]["buy_order_price"].ToString();
                    string commodity_name = ds.Rows[0]["commodity_name"].ToString();
                    string user_companyname = ds.Rows[0]["user_companyname"].ToString();
                    string user_name = ds.Rows[0]["user_name"].ToString();
                    string user_phone = ds.Rows[0]["user_phone"].ToString();

                    #region 给修理厂发微信消息
                    {
                        var user_binduserid = mainsql1.SqlExecuteScalar($"select user_binduserid from {BIAOUSERCOMPANY} where user_id='{company_id}'").ToString();
                        var ids = user_binduserid.Split(",".ToArray(), StringSplitOptions.RemoveEmptyEntries);
                        var user_onlyids = string.Join("','", ids);
                        var userModel = mainsql1.SqlExcuteWithReturn($"select user_openid_juhesheng from {BIAOUSER} where user_phone IN ('{user_onlyids}')  ").ToModels();

                        foreach (var uitem in userModel)
                        {
                            var openid = uitem["user_openid_juhesheng"];

                            if (!string.IsNullOrWhiteSpace(openid))
                            {
                                //发送消息
                                WebServiceShopping.wechartTools.SendMsgGZH(new WebServiceShopping.wechartTools.PayOKMsg()
                                {
                                    //miniprogram = new WebServiceShopping.wechartTools.XCXPath()
                                    //{
                                    //    pagepath = $"/pages/my/repairfactory/index/index?companyid={repair_companyid}"
                                    //},
                                    touser = openid,
                                    data = new WebServiceShopping.wechartTools.PayOKMsg.DataModel()
                                    {
                                        first = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = $"您的客户已经付款！"
                                        },
                                        keyword1 = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = $"{user_name}{user_phone}"
                                        },
                                        keyword2 = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = buy_order_price + "元"
                                        },
                                        keyword3 = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = user_companyname
                                        },
                                        keyword4 = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = DateTime.Now.ToString("yyyy年MM月dd HH:mm")
                                        },
                                        remark = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = $"您的客户已经付款！"
                                        },
                                    }
                                });
                            }
                        }
                    }

                    #endregion
                }
                mainsql1.closesql();
            }
            catch (Exception ex)
            {
                logJieKou.Info("聚合支付异常-" + ex.Message);
                goto EXIT;
            }
            ret.Byte_Flag = (sbyte)1;
            ret.Map_Args["ErrorMsg"] = "操作成功";
        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }

        //用户确认门店商品支付失败
        [WebMethod(Description = "用户确认门店商品支付失败")]
        public string Yonghu_StorePaymenCancel(string msg)
        {
            ILog logJieKou = LogManager.GetLogger("LoggerZhiFu");
            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv);
            mysqlcli mainsql = new mysqlcli();

            try
            {
                logJieKou.Info("请求传化支付商品订单费用Cancel-");
                string orderId = comrcv.Map_Args["orderId"];
                string qgliushuinumber = comrcv.Map_Args["qgliushuinumber"];

                tuangou_huidiao(orderId, qgliushuinumber, false, logJieKou);

            }
            catch (Exception ex)
            {
                logJieKou.Info("聚合支付异常-" + ex.Message);

                goto EXIT;
            }
            ret.Byte_Flag = (sbyte)1;
        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }


        //修理厂请求提现
        [WebMethod(Description = "正式版本")]
        public string Company_Asktixian_Lq(string msg)
        {
            ILog logJieKou = LogManager.GetLogger("LoggerZhiFu");
            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv);
            mysqlcli mainsql = new mysqlcli();
            string qgliushuinumber = "";
            try
            {
                logJieKou.Info("修理厂请求提现-");
                string company_id = comrcv.Map_Args["company_id"];
                string jine = comrcv.Map_Args["cost"];                      //金额
                string openid = comrcv.Map_Args["openid"];
                string phone = comrcv.Map_Args["phone"];
                string bankname = comrcv.Map_Args["bankname"];
                string username = comrcv.Map_Args["username"];
                string bankcardid = comrcv.Map_Args["bankcardid"];
                string chbusinessrecordnumber = "";
                string companynumber = "";
                string companyname = "";


                #region 查支付公司表的信息
                using (TransactionScope tsall1 = new TransactionScope())
                {



                    mainsql.openShopServicesql();
                    string sqlcmd = string.Format("SELECT * from {0} where com_account='qingguan' AND com_number='00000' ;", BIAOQGZHIFUCOMPANY);
                    DataTable ds = mainsql.SqlExcuteWithReturn(sqlcmd);
                    if (ds.Rows.Count == 0)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "没有流水记录";
                        goto EXIT;
                    }

                    string qgnumber = ds.Rows[0]["com_number"].ToString();
                    string qgnumberdate = ds.Rows[0]["com_numberdate"].ToString();

                    qgliushuinumber = qgnumber + DateTime.Now.ToString("yyyyMMddHHmmss") + GetCompanyDDNumber(mainsql, qgnumberdate, "qingguan");


                    ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} WHERE user_id='{1}'", BIAOUSERCOMPANY, company_id));
                    if (ds.Rows.Count == 0)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "没有找到修理厂信息";
                        goto EXIT;
                    }
                    double comjine = 0;
                    comjine = ds.Rows[0]["user_price"].ToDouble();

                    double txjine = 0;

                    double.TryParse(jine, out txjine);

                    if (comjine < txjine)
                    {
                        ret.Map_Args["ErrorMsg"] = "修理厂余额不足";  //参数错误
                        goto EXIT;
                    }
                    sqlcmd = string.Format("INSERT INTO {0} (zf_time,zf_type,zf_status,zf_qgnumber,zf_chnumber,zf_companyaccount," +
                    "zf_companynumber,zf_companyname,zf_companyamount,zf_qgamount,zf_default,zf_zfphone,zf_way,zf_shouzhi,zf_comshouzhi)" +
                    " VALUES ('{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','零钱','0','2')",
                    BIAOQGZHIFURECORD + DateTime.Now.ToString("yyyyMM"), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "修理厂零钱提现", "等待支付", qgliushuinumber,
                    chbusinessrecordnumber, company_id, companynumber, companyname, txjine.ToString("0.00"), txjine.ToString("0.00"), "修理厂零钱提现", phone);

                    int sqlret = mainsql.SqlExcuteNoReturn(sqlcmd);
                    if (sqlret != 1)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "插入记录失败";
                        goto EXIT;
                    }
                    mainsql.closesql();
                    tsall1.Complete();
                }
                #endregion


                #region 调用传化接口
                string subjectstring = companyname + "-公司提现";
                string qgppid = QGZHIFUQGAPPID;
                string chappid = QGZHIFUCHAPPID;
                string sk = QGZHIFUCHSK;
                string com_accountnumber = QGZHIFUACCOUNTNUMBER;

                string logip = "";
                try
                {
                    logip = Context.Request.ServerVariables.Get("Remote_Addr").ToString();
                }
                catch
                { }
                String service_id = "tf56enterprise.enterprise.payForCustomer";
                Dictionary<string, object> paramMap = new Dictionary<string, object>();
                //公共参数
                paramMap.Add("appid", chappid);
                paramMap.Add("tf_timestamp", DateTime.Now.ToString("yyyyMMddHHmmss"));
                paramMap.Add("service_id", service_id);
                paramMap.Add("sign_type", "RSA");
                paramMap.Add("businessnumber", qgliushuinumber);
                paramMap.Add("subject", "修理厂提现");
                paramMap.Add("transactionamount", jine);
                paramMap.Add("bankcardnumber", bankcardid);
                paramMap.Add("bankcardname", username);
                paramMap.Add("bankname", bankname);
                paramMap.Add("bankcardtype", "个人");
                paramMap.Add("bankaccounttype", "储蓄卡");
                paramMap.Add("backurl", XCXBACKURL);
                paramMap.Add("fromaccountnumber", com_accountnumber);
                paramMap.Add("terminal", "Android");
                string tf_sign = signForm(paramMap, sk);
                paramMap.Add("tf_sign", tf_sign);
                paramMap.Remove("dog_sk");
                string retsult = PostWebRequestForm(baseurl, paramMap);
                JObject retsultJson = JsonConvert.DeserializeObject(retsult) as JObject;
                logJieKou.Info("结果数据：\n" + retsultJson.ToString());
                string coderel = retsultJson["code"].ToString();
                string result = retsultJson["result"].ToString();
                string cuomsg = retsultJson["msg"].ToString();
                string retdata = retsultJson["data"].ToString();
                ret.Map_Args["ErrorMsg"] = cuomsg;
                logJieKou.Info("结果数据：\n" + result.ToString());
                if (result.Equals("success"))
                {
                    mainsql.openShopServicesql();
                    JObject alldataJson = JsonConvert.DeserializeObject(retdata) as JObject;
                    chbusinessrecordnumber = alldataJson["businessrecordnumber"].ToString();
                    //定时查询支付状态  
                    int count = CHAXUNTIME;
                    int interval = 1000;
                    ret.Map_Args["ErrorMsg"] = "处理中";
                    for (int i = 1; i <= count; i++)
                    {
                        string sqlcmd = string.Format("select * from {0} where zf_qgnumber = '{1}' ;",
                             BIAOQGZHIFURECORD + DateTime.Now.ToString("yyyyMM"), qgliushuinumber);
                        DataTable ds = mainsql.SqlExcuteWithReturn(sqlcmd);
                        if (ds.Rows.Count == 0)
                        {
                            mainsql.closesql();
                            ds.Dispose();
                            ret.Map_Args["ErrorMsg"] = "没有流水记录";
                            goto EXIT;
                        }

                        string zf_status = ds.Rows[0]["zf_status"].ToString();
                        if (zf_status.Equals("支付成功"))
                        {
                            mainsql.closesql();
                            ds.Dispose();
                            break;
                        }
                        else if (zf_status.Equals("支付失败"))
                        {
                            mainsql.closesql();
                            ds.Dispose();
                            ret.Map_Args["ErrorMsg"] = ds.Rows[0]["zf_default"].ToString();
                            goto EXIT;
                        }
                        Thread.Sleep(interval);
                    }

                }
                else
                {

                    ret.Map_Args["ErrorMsg"] = "聚合支付返回错误信息" + cuomsg;  //参数错误
                    goto EXIT;
                }

                #endregion
            }

            catch (Exception ex)
            {
                logJieKou.Info("聚合支付异常-" + ex.Message);
                mainsql.closesql();
                goto EXIT;
            }
            ret.Byte_Flag = (sbyte)1;
        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }

        //用户请求提现
        [WebMethod(Description = "正式版本")]
        public string Yonghu_Asktixian_Lq(string msg)
        {
            ILog logJieKou = LogManager.GetLogger("LoggerZhiFu");
            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv);
            mysqlcli mainsql = new mysqlcli();
            string qgliushuinumber = "";
            try
            {
                logJieKou.Info("修理厂请求提现-");
                string user_id = comrcv.Map_Args["user_id"];
                string jine = comrcv.Map_Args["cost"];                      //金额
                string openid = comrcv.Map_Args["openid"];
                string phone = comrcv.Map_Args["phone"];
                string bankname = comrcv.Map_Args["bankname"];
                string username = comrcv.Map_Args["username"];
                string bankcardid = comrcv.Map_Args["bankcardid"];
                string chbusinessrecordnumber = "";

                #region 查支付公司表的信息

                using (TransactionScope tsall1 = new TransactionScope())
                {



                    mainsql.openShopServicesql();
                    qgliushuinumber = GetLdpLiushui(mainsql);

                    var ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} WHERE user_onlyid='{1}'", BIAOYONGHUUSER, user_id));
                    if (ds.Rows.Count == 0)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "没有找到用户信息";
                        goto EXIT;
                    }
                    double comjine = 0;
                    comjine = ds.Rows[0]["user_balance"].ToDouble();

                    double txjine = 0;

                    double.TryParse(jine, out txjine);

                    if (comjine < txjine)
                    {
                        ret.Map_Args["ErrorMsg"] = "余额不足";  //参数错误
                        goto EXIT;
                    }
                    string sqlcmd = string.Format("INSERT INTO {0} (zf_time,zf_type,zf_status,zf_qgnumber,zf_chnumber,zf_zfonlyid," +
                    "zf_yhamount,zf_qgamount,zf_default,zf_zfphone,zf_way,zf_shouzhi,zf_comshouzhi)" +
                    " VALUES ('{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','零钱','0','2')",
                    BIAOQGZHIFURECORD + DateTime.Now.ToString("yyyyMM"), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "用户零钱提现", "等待支付", qgliushuinumber,
                    chbusinessrecordnumber, user_id, txjine.ToString("0.00"), txjine.ToString("0.00"), "用户零钱提现", phone);

                    int sqlret = mainsql.SqlExcuteNoReturn(sqlcmd);
                    if (sqlret != 1)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "插入记录失败";
                        goto EXIT;
                    }
                    mainsql.closesql();
                    tsall1.Complete();
                }
                #endregion


                #region 调用传化接口

                string qgppid = QGZHIFUQGAPPID;
                string chappid = QGZHIFUCHAPPID;
                string sk = QGZHIFUCHSK;
                string com_accountnumber = QGZHIFUACCOUNTNUMBER;

                string logip = "";
                try
                {
                    logip = Context.Request.ServerVariables.Get("Remote_Addr").ToString();
                }
                catch
                { }
                String service_id = "tf56enterprise.enterprise.payForCustomer";
                Dictionary<string, object> paramMap = new Dictionary<string, object>();
                //公共参数
                paramMap.Add("appid", chappid);
                paramMap.Add("tf_timestamp", DateTime.Now.ToString("yyyyMMddHHmmss"));
                paramMap.Add("service_id", service_id);
                paramMap.Add("sign_type", "RSA");
                paramMap.Add("businessnumber", qgliushuinumber);
                paramMap.Add("subject", "用户提现");
                paramMap.Add("transactionamount", jine);
                paramMap.Add("bankcardnumber", bankcardid);
                paramMap.Add("bankcardname", username);
                paramMap.Add("bankname", bankname);
                paramMap.Add("bankcardtype", "个人");
                paramMap.Add("bankaccounttype", "储蓄卡");
                paramMap.Add("backurl", XCXBACKURL);
                paramMap.Add("fromaccountnumber", com_accountnumber);
                paramMap.Add("terminal", "Android");
                string tf_sign = signForm(paramMap, sk);
                paramMap.Add("tf_sign", tf_sign);
                paramMap.Remove("dog_sk");
                string retsult = PostWebRequestForm(baseurl, paramMap);
                JObject retsultJson = JsonConvert.DeserializeObject(retsult) as JObject;
                logJieKou.Info("结果数据：\n" + retsultJson.ToString());
                string coderel = retsultJson["code"].ToString();
                string result = retsultJson["result"].ToString();
                string cuomsg = retsultJson["msg"].ToString();
                string retdata = retsultJson["data"].ToString();
                ret.Map_Args["ErrorMsg"] = cuomsg;
                logJieKou.Info("结果数据：\n" + result.ToString());
                if (result.Equals("success"))
                {
                    mainsql.openShopServicesql();
                    JObject alldataJson = JsonConvert.DeserializeObject(retdata) as JObject;
                    chbusinessrecordnumber = alldataJson["businessrecordnumber"].ToString();
                    //定时查询支付状态  
                    int count = CHAXUNTIME;
                    int interval = 1000;
                    ret.Map_Args["ErrorMsg"] = "处理中";
                    for (int i = 1; i <= count; i++)
                    {
                        string sqlcmd = string.Format("select * from {0} where zf_qgnumber = '{1}' ;",
                             BIAOQGZHIFURECORD + DateTime.Now.ToString("yyyyMM"), qgliushuinumber);
                        DataTable ds = mainsql.SqlExcuteWithReturn(sqlcmd);
                        if (ds.Rows.Count == 0)
                        {
                            mainsql.closesql();
                            ds.Dispose();
                            ret.Map_Args["ErrorMsg"] = "没有流水记录";
                            goto EXIT;
                        }

                        string zf_status = ds.Rows[0]["zf_status"].ToString();
                        if (zf_status.Equals("支付成功"))
                        {
                            mainsql.closesql();
                            ds.Dispose();
                            break;
                        }
                        else if (zf_status.Equals("支付失败"))
                        {
                            mainsql.closesql();
                            ds.Dispose();
                            ret.Map_Args["ErrorMsg"] = ds.Rows[0]["zf_default"].ToString();
                            goto EXIT;
                        }
                        Thread.Sleep(interval);
                    }

                }
                else
                {

                    ret.Map_Args["ErrorMsg"] = "聚合支付返回错误信息" + cuomsg;  //参数错误
                    goto EXIT;
                }

                #endregion
            }

            catch (Exception ex)
            {
                logJieKou.Info("聚合支付异常-" + ex.Message);
                mainsql.closesql();
                goto EXIT;
            }
            ret.Byte_Flag = (sbyte)1;
        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }



        #endregion

        #region 维修流程接口

        #region 用户流程

        [WebMethod(Description = "用户下单修理")]//1-0-0;发消息给修理厂
        public string YongHu_SetRepair(string msg)
        {
            ILog loginfo = LogManager.GetLogger("LoggerJieKou");

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);
            mysqlcli mainsql = new mysqlcli();

            try
            {


                string repair_yonghuid = comrcv.Map_Args["repair_yonghuid"];//用户的id
                string repair_yonghuname = comrcv.Map_Args["repair_yonghuname"];//用户的姓名
                string repair_yonghuphone = comrcv.Map_Args["repair_yonghuphone"];//用户的电话
                string repair_companyid = comrcv.Map_Args["repair_companyid"];//修理厂的id
                string repair_companyname = comrcv.Map_Args["repair_companyname"];//修理厂的名称

                string repair_service = comrcv.Map_Args["repair_service"];//101.011.100.001.010.000。分别代表拖车.接车.送车

                string repair_yhlongitude = comrcv.Map_Args["repair_yhlongitude"];//用户的经纬度，可以不传，不传为空
                string repair_yhlatitude = comrcv.Map_Args["repair_yhlatitude"];//用户的经纬度，可以不传，不传为空
                string repair_carinfo = comrcv.Map_Args["repair_carinfo"];//汽车内容，可以不传，不传为空

                string repair_serviceprice = comrcv.Map_Args["repair_serviceprice"];//服务费用，没有传0


                string repair_xunjiaid = comrcv.Map_Args.ContainsKey("repair_xunjiaid") ? comrcv.Map_Args["repair_xunjiaid"] : "";

                string repair_carplate = comrcv.Map_Args.ContainsKey("repair_carplate") ? comrcv.Map_Args["repair_carplate"] : "";

                string repair_default = comrcv.Map_Args.ContainsKey("repair_default") ? comrcv.Map_Args["repair_default"] : "";//备注信息




                using (TransactionScope tsall = new TransactionScope())
                {
                    mainsql.openShopServicesql();

                    string repair_id = getrepairid(mainsql);

                    //插入维修记录
                    string intsertkeystr = SQLYONGHUREPAIR;
                    string intsertvaluestr = SQLYONGHUREPAIR;
                    intsertvaluestr = intsertvaluestr.Replace("repair_id", "'" + repair_id + "'");//
                    intsertvaluestr = intsertvaluestr.Replace("repair_createtime", "'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'");//
                    intsertvaluestr = intsertvaluestr.Replace("repair_yonghuid", "'" + repair_yonghuid + "'");//
                    intsertvaluestr = intsertvaluestr.Replace("repair_yonghuname", "'" + repair_yonghuname + "'");//
                    intsertvaluestr = intsertvaluestr.Replace("repair_yonghuphone", "'" + repair_yonghuphone + "'");//
                    intsertvaluestr = intsertvaluestr.Replace("repair_companyid", "'" + repair_companyid + "'");//
                    intsertvaluestr = intsertvaluestr.Replace("repair_companyname", "'" + repair_companyname + "'");//
                    intsertvaluestr = intsertvaluestr.Replace("repair_service,", "'" + repair_service + "',");//
                    intsertvaluestr = intsertvaluestr.Replace("repair_yhlongitude", "'" + repair_yhlongitude + "'");//
                    intsertvaluestr = intsertvaluestr.Replace("repair_yhlatitude", "'" + repair_yhlatitude + "'");//
                    intsertvaluestr = intsertvaluestr.Replace("repair_carinfo", "'" + repair_carinfo + "'");//
                    intsertvaluestr = intsertvaluestr.Replace("repair_carplate", "'" + repair_carplate + "'");//

                    intsertvaluestr = intsertvaluestr.Replace("repair_status1", "'1'");//
                    intsertvaluestr = intsertvaluestr.Replace("repair_status2", "'0'");//
                    intsertvaluestr = intsertvaluestr.Replace("repair_status3", "'0'");//

                    intsertvaluestr = intsertvaluestr.Replace("repair_repairinfo,", "'',");// 维修内容及工时费，用json，比如{基础保养-50元,换刹车片，100元}
                    intsertvaluestr = intsertvaluestr.Replace("repair_repairinfo_products,", "'',");// // 维修所需材料，用json，比如{机油,机滤,刹车片}
                    intsertvaluestr = intsertvaluestr.Replace("repair_xunjiaid", "'" + repair_xunjiaid + "'");//
                    intsertvaluestr = intsertvaluestr.Replace("repair_baojiaid", "''");//

                    intsertvaluestr = intsertvaluestr.Replace("repair_serviceprice,", "'" + repair_serviceprice + "',");////服务费用
                    intsertvaluestr = intsertvaluestr.Replace("repair_productprice", "'0'");//材料费用
                    intsertvaluestr = intsertvaluestr.Replace("repair_gongshiprice", "'0'");//工时费用
                    intsertvaluestr = intsertvaluestr.Replace("repair_allprice,", "'" + repair_serviceprice + "',");//所有费用
                    intsertvaluestr = intsertvaluestr.Replace("repair_paystatus", "'0'");//支付状态
                    intsertvaluestr = intsertvaluestr.Replace("repair_default", "''");//

                    string cmd = string.Format("insert into {0} ({1}) values ({2}) ", BIAOUSERREPAIR, intsertkeystr, intsertvaluestr);
                    int sqlret = mainsql.SqlExcuteNoReturn(cmd);
                    if (sqlret != 1)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "下单失败";
                        goto EXIT;
                    }


                    #region 发微信消息
                    {

                        string fuwuneirong = "客户选择：";
                        bool selectflah = false;
                        if (repair_service.Substring(0, 1) == "1")
                        {
                            fuwuneirong += " 【拖车】 ";
                            selectflah = true;
                        }
                        if (repair_service.Substring(1, 1) == "1")
                        {
                            fuwuneirong += " 【接车】 "; selectflah = true;
                        }
                        if (repair_service.Substring(2, 1) == "1")
                        {
                            fuwuneirong += " 【送车】 "; selectflah = true;
                        }
                        if (selectflah == false)
                        {
                            fuwuneirong = "客户未选择接送车服务";
                        }
                        var user_binduserid = mainsql.SqlExecuteScalar($"select user_binduserid from {BIAOUSERCOMPANY} where user_id='{repair_companyid}'").ToString();
                        var ids = user_binduserid.Split(",".ToArray(), StringSplitOptions.RemoveEmptyEntries);
                        var user_onlyids = string.Join("','", ids);
                        var userModel = mainsql.SqlExcuteWithReturn($"select user_openid_juhesheng from {BIAOUSER} where user_phone IN ('{user_onlyids}')  ").ToModels();

                        var userIds = new List<string>();

                        foreach (var uitem in userModel)
                        {
                            userIds.Add(uitem["user_openid_juhesheng"]);
                        }

                        var ps = mainsql.SqlExecuteScalar($"select c_name from {BIAOSHOPCONFIG} where c_type='xunjiamsg'")?.ToString();
                        if (!string.IsNullOrWhiteSpace(ps))
                        {
                            loginfo.Error(ps);
                            var ss = ps.Split(",".ToArray(), StringSplitOptions.RemoveEmptyEntries);
                            if (ss.Length > 0)
                            {
                                var users = mainsql.SqlExcuteWithReturn($"select user_openid_juhesheng,user_phone,user_name,user_onlyid from {BIAOUSER} where user_phone in ('{string.Join("','", ss)}')").ToModels();
                                foreach (var item in users)
                                {
                                    if (!userIds.Contains(item["user_openid_juhesheng"]))
                                    {
                                        userIds.Add(item["user_openid_juhesheng"]);
                                    }
                                }
                            }
                        }

                        foreach (string openid in userIds)
                        {
                            if (!string.IsNullOrWhiteSpace(openid))
                            {
                                WebServiceShopping.wechartTools.SendMsgGZH(new WebServiceShopping.wechartTools.YuYueMsg()
                                {
                                    miniprogram = new WebServiceShopping.wechartTools.XCXPath()
                                    {
                                        pagepath = $"/pages/my/repairfactory/index/index?companyid={repair_companyid}"
                                    },
                                    touser = openid,
                                    data = new WebServiceShopping.wechartTools.YuYueMsg.DataModel()
                                    {
                                        first = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = "您有新的预约订单！"
                                        },
                                        keyword1 = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = repair_yonghuname
                                        },
                                        keyword2 = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = repair_yonghuphone
                                        },
                                        keyword3 = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = fuwuneirong
                                        },
                                        keyword4 = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = "1"
                                        },
                                        keyword5 = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = DateTime.Now.ToString("yyyy年MM月dd HH:mm")
                                        }

                                    }
                                });
                            }
                        }
                    }

                    #endregion



                    ret.Map_Args.Add("repair_id", repair_id);
                    mainsql.closesql();
                    tsall.Complete();
                    ret.Byte_Flag = (sbyte)1;
                }

            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                loginfo.Info(ex);
            }





        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }

        [WebMethod(Description = "用户取消下单")]//3-0-0
        public string YongHu_DelRepair(string msg)
        {
            ILog loginfo = LogManager.GetLogger("LoggerJieKou");

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);
            mysqlcli mainsql = new mysqlcli();
            mainsql.openShopServicesql();
            try
            {

                var repair_id = comrcv.Map_Args["repair_id"];


                using (TransactionScope tsall = new TransactionScope())
                {

                    string sqlwhere = string.Format("WHERE repair_id ='{0}' ", repair_id);


                    var ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} {1};", BIAOUSERREPAIR, sqlwhere));
                    if (ds.Rows.Count == 0)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "没有相关订单";
                        goto EXIT;
                    }


                    string cmd = string.Format(" delete from {0} where repair_id ='{1}' ;", BIAOUSERREPAIR, repair_id);
                    int retint = mainsql.SqlExcuteNoReturn(cmd);
                    if (retint != 1)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "用户取消接单失败";
                        goto EXIT;
                    }



                    mainsql.closesql();
                    tsall.Complete();
                    ret.Byte_Flag = (sbyte)1;
                }

            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                loginfo.Info(ex);
            }

        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }



        [WebMethod(Description = "用户确认检测结果")]//3-4-0
        public string Yonghu_SureRepairCheckend(string msg)
        {
            ILog loginfo = LogManager.GetLogger("LoggerJieKou");

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);
            mysqlcli mainsql = new mysqlcli();
            mainsql.openShopServicesql();
            try
            {
                var repair_id = comrcv.Map_Args["repair_id"];

                var repair_repairinfo_products = comrcv.Map_Args["repair_repairinfo_products"];//维修材料json

                var user_id = comrcv.Map_Args["user_id"];
                var content = comrcv.Map_Args["Content"];
                var fileIds = comrcv.Map_Args["files"];
                var ids = comrcv.Map_Args["carid"].Split(",".ToArray(), StringSplitOptions.RemoveEmptyEntries).ToArray();
                var carid = string.Join(",", ids);
                var products = comrcv.Map_Args["products"];



                using (TransactionScope tsall = new TransactionScope())
                {

                    string sqlwhere = string.Format("WHERE repair_id ='{0}' ", repair_id);

                    var ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} {1} ;", BIAOUSERREPAIR, sqlwhere));
                    if (ds.Rows.Count == 0)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "没有相关订单";
                        goto EXIT;
                    }
                    if (ds.Rows[0]["repair_status1"].ToString() != "3")
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "订单状态异常";
                        goto EXIT;
                    }
                    if (ds.Rows[0]["repair_status2"].ToString() != "2")
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "订单状态异常";
                        goto EXIT;
                    }


                    string repair_companyid = ds.Rows[0]["repair_companyid"].ToString();
                    string repair_carplate = ds.Rows[0]["repair_carplate"].ToString();
                    string repair_yonghuname = ds.Rows[0]["repair_yonghuname"].ToString();
                    string updatestr = string.Format(" repair_status1='3',repair_status2='4' ");

                    //  updatestr += string.Format(" ,repair_repairinfo='{0}' ", repair_repairinfo);
                    updatestr += string.Format(" ,repair_repairinfo_products='{0}' ", repair_repairinfo_products);
                    //  updatestr += string.Format(" ,repair_gongshiprice='{0}' ", repair_gongshiprice);
                    string cmd = string.Format(" update {0} set {1} where repair_id ='{2}' ;", BIAOUSERREPAIR, updatestr, repair_id);
                    int retint = mainsql.SqlExcuteNoReturn(cmd);
                    if (retint != 1)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "用户确认检测结果失败";
                        goto EXIT;
                    }

                    #region 向修理厂发微信消息
                    {


                        var user_binduserid = mainsql.SqlExecuteScalar($"select user_binduserid from {BIAOUSERCOMPANY} where user_id='{repair_companyid}'").ToString();
                        ids = user_binduserid.Split(",".ToArray(), StringSplitOptions.RemoveEmptyEntries);
                        var user_onlyids = string.Join("','", ids);
                        var userModel = mainsql.SqlExcuteWithReturn($"select user_openid_juhesheng from {BIAOUSER} where user_phone IN ('{user_onlyids}')  ").ToModels();

                        foreach (var uitem in userModel)
                        {
                            var openid = uitem["user_openid_juhesheng"];
                            loginfo.Info("获取open:" + openid);
                            if (!string.IsNullOrWhiteSpace(openid))
                            {
                                //发送消息
                                WebServiceShopping.wechartTools.SendMsgGZH(new WebServiceShopping.wechartTools.YHCheckMsg()
                                {
                                    miniprogram = new WebServiceShopping.wechartTools.XCXPath()
                                    {
                                        pagepath = $"/pages/my/repairfactory/index/index?companyid={repair_companyid}"
                                    },
                                    touser = openid,
                                    data = new WebServiceShopping.wechartTools.YHCheckMsg.DataModel()
                                    {
                                        first = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = $"您的客户已经确认检测单！"
                                        },
                                        keyword1 = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = $"【{repair_yonghuname}】-({repair_carplate})"
                                        },
                                        keyword2 = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = DateTime.Now.ToString("yyyy年MM月dd HH:mm")
                                        },
                                    }
                                });
                            }
                        }
                    }
                    #endregion




                    JArray json = JsonConvert.DeserializeObject<JArray>(products);
                    string productscount = json.Count.ToString();
                    string productsnames = "";
                    if (json != null && json.Count > 0)
                    {
                        foreach (var item in json)
                        {
                            productsnames += "【" + item.Value<string>("name") + "】";

                        }
                    }

                    #region 获取车辆价格信息

                    var proInfo = Helper.GetShichedao(content, json, loginfo);
                    products = string.IsNullOrWhiteSpace(proInfo) ? products : proInfo;

                    #endregion

                    ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} WHERE repair_id ='{1}' ;", BIAOUSERREPAIR, repair_id));
                    if (ds.Rows.Count == 0)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "没有相关订单";
                        goto EXIT;
                    }
                    user_id = ds.Rows[0]["repair_yonghuid"].ToString();

                    string newxunjiaid = getxunjiaid(mainsql);
                    if (newxunjiaid == "")
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "获取询价编号失败";
                        goto EXIT;
                    }

                    if (mainsql.SqlExcuteNoReturn($"insert into {BIAOXUNJIA + DateTime.Now.ToString("yyyyMM")}(user_id,repair_id,xj_id,x_content,x_img_ids,x_send_time,x_deleteflag,x_car_id,x_products,x_number) "
                         + $"values('{repair_companyid}','{repair_id}','{newxunjiaid}','{content}','{fileIds}',NOW(),0,'{carid}',@product,0)", new MySqlParameter("@product", products)) != 1)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "插入字段失败";
                        goto EXIT;
                    }

                    if (!string.IsNullOrWhiteSpace(fileIds))
                        ConvertTemporary(mainsql, fileIds);

                    cmd = string.Format(" update {0} set repair_status1='3',repair_status2='4',repair_xunjiaid='{1}' where repair_id ='{2}' ;",
                        BIAOUSERREPAIR, newxunjiaid, repair_id);
                    retint = mainsql.SqlExcuteNoReturn(cmd);
                    if (retint != 1)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "用户发起询价失败";
                        goto EXIT;
                    }




                    #region 给卖家微信消息
                    var shopids = mainsql.SqlExcuteWithReturn($"select shop_id from {BIAOSHOPCAR} t1 where t1.car_type_id in ('{string.Join("','", ids)}') and t1.shop_car_deleteflag=0  group by shop_id").ToModels();


                    var userIds = new List<string>();
                    foreach (var item in shopids)
                    {
                        var shopId = item["shop_id"];
                        var users = mainsql.SqlExcuteWithReturn($"select t2.user_openid_juhesheng,t2.user_phone,t2.user_name,t2.user_onlyid from {BIAOSHOPUSER} t1 left join {BIAOUSER} t2 on t1.user_id=t2.user_onlyid where shop_id='{shopId}' and shop_user_ismsg=1 and shop_user_deleteflag<>1").ToModels();
                        foreach (var uitem in users)
                        {
                            var openid = uitem["user_openid_juhesheng"];
                            if (!string.IsNullOrWhiteSpace(openid))
                            {
                                userIds.Add(uitem["user_onlyid"]);
                                //发送消息
                                WebServiceShopping.wechartTools.SendMsgGZH(new WebServiceShopping.wechartTools.XunJiaMsg()
                                {
                                    miniprogram = new WebServiceShopping.wechartTools.XCXPath()
                                    {
                                        pagepath = "/pages/my/store/store?ShopId=" + shopId
                                    },
                                    touser = openid,
                                    data = new WebServiceShopping.wechartTools.XunJiaMsg.DataModel()
                                    {
                                        first = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = "您有新的询价单"
                                        },
                                        keyword2 = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = DateTime.Now.ToString("yyyy年MM月dd HH:mm")
                                        },
                                        keyword3 = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = productsnames
                                        },
                                        keyword1 = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = "实际询价人"
                                        },
                                        keyword4 = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = productscount
                                        }
                                    }
                                });
                            }
                        }
                    }

                    var ps = mainsql.SqlExecuteScalar($"select c_name from {BIAOSHOPCONFIG} where c_type='xunjiamsg'")?.ToString();
                    if (!string.IsNullOrWhiteSpace(ps))
                    {
                        loginfo.Error(ps);
                        var ss = ps.Split(",".ToArray(), StringSplitOptions.RemoveEmptyEntries);
                        if (ss.Length > 0)
                        {
                            var users = mainsql.SqlExcuteWithReturn($"select user_openid_juhesheng,user_phone,user_name,user_onlyid from {BIAOUSER} where user_phone in ('{string.Join("','", ss)}')").ToModels();
                            foreach (var item in users)
                            {
                                if (!userIds.Contains(item["user_onlyid"]))
                                {
                                    var openid = item["user_openid_juhesheng"];
                                    loginfo.Error(openid);
                                    if (!string.IsNullOrWhiteSpace(openid))
                                    {
                                        //发送消息
                                        WebServiceShopping.wechartTools.SendMsgGZH(new WebServiceShopping.wechartTools.XunJiaMsg()
                                        {
                                            miniprogram = null,
                                            touser = openid,
                                            data = new WebServiceShopping.wechartTools.XunJiaMsg.DataModel()
                                            {
                                                first = new WebServiceShopping.wechartTools.DataItem()
                                                {
                                                    value = "您有新的询价单"
                                                },
                                                keyword2 = new WebServiceShopping.wechartTools.DataItem()
                                                {
                                                    value = DateTime.Now.ToString("yyyy年MM月dd HH:mm")
                                                },
                                                keyword3 = new WebServiceShopping.wechartTools.DataItem()
                                                {
                                                    value = productsnames
                                                },
                                                keyword1 = new WebServiceShopping.wechartTools.DataItem()
                                                {
                                                    value = "合作修理厂"
                                                },
                                                keyword4 = new WebServiceShopping.wechartTools.DataItem()
                                                {
                                                    value = productscount
                                                }
                                            }
                                        });
                                    }
                                }
                            }
                        }
                    }
                    #endregion




                    mainsql.closesql();
                    tsall.Complete();
                    ret.Byte_Flag = (sbyte)1;
                }

            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                loginfo.Info(ex);
            }

        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }

        [WebMethod(Description = "用户选择报价")]//3-5-0
        public string Yonghu_RepairSureBaojia(string msg)
        {
            ILog loginfo = LogManager.GetLogger("LoggerJieKou");

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Maplist_MapArgs = new Dictionary<string, List<Dictionary<string, string>>>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);

            mysqlcli mainsql = new mysqlcli();

            try
            {
                using (TransactionScope tsall = new TransactionScope())
                {
                    mainsql.openShopServicesql();
                    var repair_id = comrcv.Map_Args["repair_id"];//维修单ID
                    var b_id = comrcv.Map_Args["b_id"];//报价ID

                    var repair_repairinfo_products = comrcv.Map_Args["repair_repairinfo_products"];//产品及费用

                    var shop_id = comrcv.Map_Args["shop_id"];//店铺ID

                    string repair_productprice = comrcv.Map_Args["repair_productprice"];//产品费用，没有传0


                    var ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} WHERE repair_id ='{1}' ;", BIAOUSERREPAIR, repair_id));
                    if (ds.Rows.Count == 0)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "没有相关订单";
                        goto EXIT;
                    }
                    string repair_companyid = ds.Rows[0]["repair_companyid"].ToString();
                    string repair_carplate = ds.Rows[0]["repair_carplate"].ToString();

                    string repair_yonghuname = ds.Rows[0]["repair_yonghuname"].ToString();

                    double serviceprice = 0, allprice = 0, gongshiprice = 0, productprice = 0;
                    serviceprice = ds.Rows[0]["repair_serviceprice"].ToDouble();
                    gongshiprice = ds.Rows[0]["repair_gongshiprice"].ToDouble();
                    double.TryParse(repair_productprice, out productprice);
                    allprice = serviceprice + gongshiprice + productprice;

                    string cmd = string.Format(" update {0} set  repair_status1='3',repair_status2='5',repair_status3='0',repair_baojiaid='{1}'," +
                        "repair_productprice='{2}',repair_allprice='{3}',repair_repairinfo_products='{4}',repair_shopid='{5}' where repair_id ='{6}' ;",
                        BIAOUSERREPAIR, b_id, repair_productprice, allprice, repair_repairinfo_products, shop_id, repair_id);
                    int retint = mainsql.SqlExcuteNoReturn(cmd);
                    if (retint != 1)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "用户选择报价失败";
                        goto EXIT;
                    }

                    #region 发微信消息
                    {


                        var user_binduserid = mainsql.SqlExecuteScalar($"select user_binduserid from {BIAOUSERCOMPANY} where user_id='{repair_companyid}'").ToString();
                        var ids = user_binduserid.Split(",".ToArray(), StringSplitOptions.RemoveEmptyEntries);
                        var user_onlyids = string.Join("','", ids);
                        var userModel = mainsql.SqlExcuteWithReturn($"select user_openid_juhesheng from {BIAOUSER} where user_phone IN ('{user_onlyids}')  ").ToModels();

                        foreach (var uitem in userModel)
                        {
                            var openid = uitem["user_openid_juhesheng"];
                            loginfo.Info("获取open:" + openid);
                            if (!string.IsNullOrWhiteSpace(openid))
                            {
                                //发送消息
                                WebServiceShopping.wechartTools.SendMsgGZH(new WebServiceShopping.wechartTools.YHCheckMsg()
                                {
                                    miniprogram = new WebServiceShopping.wechartTools.XCXPath()
                                    {
                                        pagepath = $"/pages/my/repairfactory/index/index?companyid={repair_companyid}"
                                    },
                                    touser = openid,
                                    data = new WebServiceShopping.wechartTools.YHCheckMsg.DataModel()
                                    {
                                        first = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = $"您的客户已经确认报价单！"
                                        },
                                        keyword1 = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = $"【{repair_yonghuname}】-({repair_carplate})"
                                        },
                                        keyword2 = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = DateTime.Now.ToString("yyyy年MM月dd HH:mm")
                                        },
                                        remark = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = $"您的客户已经选择了材料供应商，请关注支付情况！"
                                        },
                                    }
                                });
                            }
                        }
                    }
                    #endregion


                    mainsql.closesql();
                    tsall.Complete();
                    ret.Byte_Flag = (sbyte)1;
                }
            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                loginfo.Info(ex);
            }
        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }

        [WebMethod(Description = "用户确认收车")]//5-0-0
        public string Yonghu_SureRepairBackcar(string msg)
        {
            ILog loginfo = LogManager.GetLogger("LoggerJieKou");

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);
            mysqlcli mainsql = new mysqlcli();

            try
            {
                var repair_id = comrcv.Map_Args["repair_id"];

                loginfo.Info("用户确认收车--" + repair_id);
                using (TransactionScope tsall = new TransactionScope())
                {
                    mainsql.openShopServicesql();
                    string sqlwhere = string.Format("WHERE repair_id ='{0}' AND repair_status1='4' AND repair_status2='2' AND repair_status3='0'  ", repair_id);

                    var ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} {1};", BIAOUSERREPAIR, sqlwhere));
                    if (ds.Rows.Count == 0)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "没有相关订单";
                        goto EXIT;
                    }

                    string yonghuid = ds.Rows[0]["repair_yonghuid"].ToString();
                    double repair_productprice = ds.Rows[0]["repair_productprice"].ToDouble();

                    string updatestr = string.Format(" repair_status1='5',repair_status2='0',repair_status3='0' ");
                    string cmd = string.Format(" update {0} set {1} where repair_id ='{2}' ;", BIAOUSERREPAIR, updatestr, repair_id);
                    int retint = mainsql.SqlExcuteNoReturn(cmd);
                    if (retint != 1)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "用户确认交车失败";
                        goto EXIT;
                    }

                    //用户推广
                    //{
                    //    tuiguangfenrun(mainsql, repair_productprice, yonghuid, repair_id);
                    //}


                    mainsql.closesql();
                    tsall.Complete();
                    ret.Byte_Flag = (sbyte)1;
                }

            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                loginfo.Info(ex);
            }

        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }



        #endregion

        #region 修理厂流程

        [WebMethod(Description = "修理厂取消订单")]//2-0-0
        public string Company_CancelRepair(string msg)
        {
            ILog loginfo = LogManager.GetLogger("LoggerJieKou");

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);
            mysqlcli mainsql = new mysqlcli();

            try
            {

                var repair_id = comrcv.Map_Args["repair_id"];


                using (TransactionScope tsall = new TransactionScope())
                {

                    mainsql.openShopServicesql();

                    string updatestr = string.Format(" repair_status1='0',repair_status2='0' ,repair_status3='0'   ");

                    string cmd = string.Format(" update {0} set {1} where repair_id ='{2}' ;", BIAOUSERREPAIR, updatestr, repair_id);
                    int retint = mainsql.SqlExcuteNoReturn(cmd);
                    if (retint != 1)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "修理厂取消订单失败";
                        goto EXIT;
                    }



                    mainsql.closesql();
                    tsall.Complete();
                    ret.Byte_Flag = (sbyte)1;
                }

            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                loginfo.Info(ex);
            }

        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }

        [WebMethod(Description = "修理厂确认接单")]//2-0-0
        public string Company_SureRepair(string msg)
        {
            ILog loginfo = LogManager.GetLogger("LoggerJieKou");

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);
            mysqlcli mainsql = new mysqlcli();
            mainsql.openShopServicesql();
            try
            {

                var repair_id = comrcv.Map_Args["repair_id"];

                var repair_worker = comrcv.Map_Args.ContainsKey("repair_worker") ? comrcv.Map_Args["repair_worker"] : string.Empty;//传用户
                using (TransactionScope tsall = new TransactionScope())
                {

                    string sqlwhere = string.Format("WHERE repair_id ='{0}' ", repair_id);


                    var ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} {1};", BIAOUSERREPAIR, sqlwhere));
                    if (ds.Rows.Count == 0)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "没有相关订单";
                        goto EXIT;
                    }
                    string repair_yonghuid = ds.Rows[0]["repair_yonghuid"].ToString();
                    string repair_yonghuphone = ds.Rows[0]["repair_yonghuphone"].ToString();
                    string service = ds.Rows[0]["repair_service"].ToString();
                    service = service.Substring(1, 1);

                    string updatestr = string.Format(" repair_status1='3',repair_status2='0'   ");

                    updatestr += string.Format(" ,repair_worker='{0}' ", repair_worker);

                    string cmd = string.Format(" update {0} set {1} where repair_id ='{2}' ;", BIAOUSERREPAIR, updatestr, repair_id);
                    int retint = mainsql.SqlExcuteNoReturn(cmd);
                    if (retint != 1)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "修理厂确认接单失败";
                        goto EXIT;
                    }



                    mainsql.closesql();
                    tsall.Complete();
                    ret.Byte_Flag = (sbyte)1;
                }

            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                loginfo.Info(ex);
            }

        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }

        [WebMethod(Description = "修理厂安排人员接车")]//2-1-0
        public string Company_JieCheing(string msg)
        {
            ILog loginfo = LogManager.GetLogger("LoggerJieKou");

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);
            mysqlcli mainsql = new mysqlcli();
            mainsql.openShopServicesql();
            try
            {

                var repair_id = comrcv.Map_Args["repair_id"];
                var repair_jiecheren = comrcv.Map_Args["repair_jiecheren"];//张予（15023196534）

                using (TransactionScope tsall = new TransactionScope())
                {

                    string sqlwhere = string.Format("WHERE repair_id ='{0}' ", repair_id);


                    var ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} {1};", BIAOUSERREPAIR, sqlwhere));
                    if (ds.Rows.Count == 0)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "没有相关订单";
                        goto EXIT;
                    }

                    string updatestr = string.Format(" repair_status1='2'  ");


                    updatestr += string.Format(" ,repair_status2='1'  ");
                    updatestr += string.Format(" ,repair_default='{0}'  ", "接车人：" + repair_jiecheren);

                    string cmd = string.Format(" update {0} set {1} where repair_id ='{2}' ;", BIAOUSERREPAIR, updatestr, repair_id);
                    int retint = mainsql.SqlExcuteNoReturn(cmd);
                    if (retint != 1)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "修理厂确认接单失败";
                        goto EXIT;
                    }



                    mainsql.closesql();
                    tsall.Complete();
                    ret.Byte_Flag = (sbyte)1;
                }

            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                loginfo.Info(ex);
            }

        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }

        [WebMethod(Description = "修理厂人员接车返程")]//2-2-0
        public string Company_JieCheend(string msg)
        {
            ILog loginfo = LogManager.GetLogger("LoggerJieKou");

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);
            mysqlcli mainsql = new mysqlcli();
            mainsql.openShopServicesql();
            try
            {

                var repair_id = comrcv.Map_Args["repair_id"];


                using (TransactionScope tsall = new TransactionScope())
                {

                    string sqlwhere = string.Format("WHERE repair_id ='{0}' ", repair_id);


                    var ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} {1};", BIAOUSERREPAIR, sqlwhere));
                    if (ds.Rows.Count == 0)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "没有相关订单";
                        goto EXIT;
                    }

                    string updatestr = string.Format(" repair_status1='2'  ");


                    updatestr += string.Format(" ,repair_status2='2'  ");


                    string cmd = string.Format(" update {0} set {1} where repair_id ='{2}' ;", BIAOUSERREPAIR, updatestr, repair_id);
                    int retint = mainsql.SqlExcuteNoReturn(cmd);
                    if (retint != 1)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "修理厂确认接单失败";
                        goto EXIT;
                    }



                    mainsql.closesql();
                    tsall.Complete();
                    ret.Byte_Flag = (sbyte)1;
                }

            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                loginfo.Info(ex);
            }

        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }

        [WebMethod(Description = "修理厂确认到车")]//3-0-0
        public string Company_SureRepairArrive(string msg)
        {
            ILog loginfo = LogManager.GetLogger("LoggerJieKou");

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);
            mysqlcli mainsql = new mysqlcli();
            mainsql.openShopServicesql();
            try
            {

                var repair_id = comrcv.Map_Args["repair_id"];


                using (TransactionScope tsall = new TransactionScope())
                {

                    string sqlwhere = string.Format("WHERE repair_id ='{0}' ", repair_id);


                    var ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} {1};", BIAOUSERREPAIR, sqlwhere));
                    if (ds.Rows.Count == 0)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "没有相关订单";
                        goto EXIT;
                    }
                    string service = ds.Rows[0]["repair_service"].ToString();
                    service = service.Substring(1, 1);

                    string updatestr = string.Format(" repair_status1='3',repair_status2='0'   ");


                    string cmd = string.Format(" update {0} set {1} where repair_id ='{2}' ;", BIAOUSERREPAIR, updatestr, repair_id);
                    int retint = mainsql.SqlExcuteNoReturn(cmd);
                    if (retint != 1)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "修理厂确认接单失败";
                        goto EXIT;
                    }



                    mainsql.closesql();
                    tsall.Complete();
                    ret.Byte_Flag = (sbyte)1;
                }

            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                loginfo.Info(ex);
            }

        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }

        [WebMethod(Description = "修理厂确认开始检测")]//3-2-0
        public string Company_SureRepairChecking(string msg)
        {
            ILog loginfo = LogManager.GetLogger("LoggerJieKou");

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);
            mysqlcli mainsql = new mysqlcli();
            mainsql.openShopServicesql();
            try
            {

                var repair_id = comrcv.Map_Args["repair_id"];
                var repair_carinfo = comrcv.Map_Args["repair_carinfo"];//车辆信息
                var repair_carplate = comrcv.Map_Args["repair_carplate"];//车辆牌照
                var repair_repairpic_ids = comrcv.Map_Args["repair_repairpic_ids"];//文件数组，逗号隔开


                string repair_carpic = comrcv.Map_Args.ContainsKey("repair_carpic") ? comrcv.Map_Args["repair_carpic"] : "";//汽车照片


                string repair_repairinfo = comrcv.Map_Args.ContainsKey("repair_repairinfo") ? comrcv.Map_Args["repair_repairinfo"] : "";//工时类容json


                string repair_gongshiprice = comrcv.Map_Args.ContainsKey("repair_gongshiprice") ? comrcv.Map_Args["repair_gongshiprice"] : "";//工时费金额



                string repair_repairinfo_products = comrcv.Map_Args.ContainsKey("repair_repairinfo_products") ? comrcv.Map_Args["repair_repairinfo_products"] : "";//维修材料json

                string repair_carmileage = comrcv.Map_Args.ContainsKey("repair_carmileage") ? comrcv.Map_Args["repair_carmileage"] : "0";
                using (TransactionScope tsall = new TransactionScope())
                {

                    string sqlwhere = string.Format("WHERE repair_id ='{0}' ", repair_id);


                    var ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} {1};", BIAOUSERREPAIR, sqlwhere));
                    if (ds.Rows.Count == 0)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "没有相关订单";
                        goto EXIT;
                    }
                    var repair_xunjiaid = ds.Rows[0]["repair_xunjiaid"].ToString();
                    string repair_yonghuid = ds.Rows[0]["repair_yonghuid"].ToString();
                    string repair_companyname = ds.Rows[0]["repair_companyname"].ToString();


                    string updatestr = "";

                    updatestr = string.Format(" repair_status1='3',repair_status2='2' ");

                    if (repair_xunjiaid != "")
                    {
                        if (repair_xunjiaid != "undefined")
                        {
                            updatestr = string.Format(" repair_status1='3',repair_status2='4' ");
                        }
                    }

                    if (repair_repairinfo_products != "")
                    {
                        updatestr += string.Format(" ,repair_repairinfo_products='{0}' ", repair_repairinfo_products);
                    }
                    else
                    {
                        updatestr = string.Format(" repair_status1='3',repair_status2='5' ");
                        updatestr += string.Format(" ,repair_productprice='{0}' ", 0);
                        updatestr += string.Format(" ,repair_allprice='{0}' ", repair_gongshiprice);
                    }



                    if (repair_carinfo != "")
                    {
                        updatestr += string.Format(" ,repair_carinfo='{0}' ", repair_carinfo);
                    }
                    if (repair_carplate != "")
                    {
                        updatestr += string.Format(" ,repair_carplate='{0}' ", repair_carplate);
                    }
                    if (repair_repairpic_ids != "")
                    {
                        updatestr += string.Format(" ,repair_repairpic_ids='{0}' ", repair_repairpic_ids);
                    }

                    if (repair_carpic != "")
                    {
                        updatestr += string.Format(" ,repair_carpic='{0}' ", repair_carpic);
                    }

                    if (repair_repairinfo != "")
                    {
                        updatestr += string.Format(" ,repair_repairinfo='{0}' ", repair_repairinfo);
                    }
                    if (repair_gongshiprice != "")
                    {
                        updatestr += string.Format(" ,repair_gongshiprice='{0}' ", repair_gongshiprice);
                    }




                    updatestr += string.Format(" ,repair_carmileage='{0}' ", repair_carmileage);


                    string cmd = string.Format(" update {0} set {1} where repair_id ='{2}' ;", BIAOUSERREPAIR, updatestr, repair_id);
                    int retint = mainsql.SqlExcuteNoReturn(cmd);
                    if (retint != 1)
                    {
                        ret.Map_Args["ErrorMsg"] = "修理厂确认开始检测失败";
                        goto EXIT;
                    }

                    if (!string.IsNullOrWhiteSpace(repair_repairpic_ids))
                        ConvertTemporary(mainsql, repair_repairpic_ids);

                    if (!string.IsNullOrWhiteSpace(repair_carpic))
                        ConvertTemporary(mainsql, repair_carpic);

                    #region 发微信消息
                    {

                        var userModel = mainsql.SqlExcuteWithReturn($"select user_xcxopenid from {BIAOUSER} where user_onlyid IN ('{repair_yonghuid}')  ").ToModels();

                        foreach (var uitem in userModel)
                        {
                            var openid = uitem["user_xcxopenid"];
                            loginfo.Info(openid);
                            if (!string.IsNullOrWhiteSpace(openid))
                            {
                                //发送消息
                                WebServiceShopping.wechartTools.SendMsg(new WebServiceShopping.wechartTools.CheckInfo()
                                {

                                    page = $"/pages/orderCenter/orderCenter?tabindex=1&yonghuid={repair_yonghuid}",
                                    touser = openid,
                                    data = new WebServiceShopping.wechartTools.CheckInfo.DataModel()
                                    {
                                        thing10 = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = repair_companyname
                                        },
                                        thing3 = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = "检测结果已出"
                                        },

                                        time2 = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = DateTime.Now.ToString("yyyy年MM月dd HH:mm")
                                        },
                                        thing4 = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = $"请进入小程序确认检测结果。"
                                        }

                                    }
                                });
                            }
                        }
                    }
                    #endregion



                    mainsql.closesql();
                    tsall.Complete();
                    ret.Byte_Flag = (sbyte)1;
                }

            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                loginfo.Info(ex);
            }

        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }

        [WebMethod(Description = "修理厂确认检测结束")]//3-2-0
        public string Company_SureRepairCheckend(string msg)
        {
            ILog loginfo = LogManager.GetLogger("LoggerJieKou");

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);
            mysqlcli mainsql = new mysqlcli();
            mainsql.openShopServicesql();
            try
            {
                var repair_id = comrcv.Map_Args["repair_id"];
                var repair_carinfo = comrcv.Map_Args["repair_carinfo"];//车辆信息
                                                                       //        var repair_repairpic_ids = comrcv.Map_Args["repair_repairpic_ids"];//图片
                var repair_repairinfo = comrcv.Map_Args["repair_repairinfo"];//维修类容json
                var repair_repairinfo_products = comrcv.Map_Args["repair_repairinfo_products"];//维修材料json

                using (TransactionScope tsall = new TransactionScope())
                {
                    //   ConvertTemporary(mainsql, repair_repairpic_ids);
                    string sqlwhere = string.Format("WHERE repair_id ='{0}' ", repair_id);

                    var ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} {1};", BIAOUSERREPAIR, sqlwhere));
                    if (ds.Rows.Count == 0)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "没有相关订单";
                        goto EXIT;
                    }

                    string repair_xunjiaid = ds.Rows[0]["repair_xunjiaid"].ToString();
                    string repair_yonghuid = ds.Rows[0]["repair_yonghuid"].ToString();
                    string repair_companyname = ds.Rows[0]["repair_companyname"].ToString();
                    string updatestr = string.Format(" repair_status1='3',repair_status2='2' ");
                    if (repair_xunjiaid != "")
                    {
                        updatestr = string.Format(" repair_status1='3',repair_status2='4' ");
                    }



                    //  updatestr += string.Format(" ,repair_repairpic_ids='{0}' ", repair_repairpic_ids);
                    updatestr += string.Format(" ,repair_repairinfo='{0}' ", repair_repairinfo);
                    updatestr += string.Format(" ,repair_repairinfo_products='{0}' ", repair_repairinfo_products);
                    updatestr += string.Format(" ,repair_carinfo='{0}' ", repair_carinfo);

                    string cmd = string.Format(" update {0} set {1} where repair_id ='{2}' ;", BIAOUSERREPAIR, updatestr, repair_id);
                    int retint = mainsql.SqlExcuteNoReturn(cmd);
                    if (retint != 1)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "修理厂确认检测结果失败";
                        goto EXIT;
                    }

                    #region 发微信消息
                    {

                        var userModel = mainsql.SqlExcuteWithReturn($"select user_xcxopenid from {BIAOUSER} where user_onlyid IN ('{repair_yonghuid}')  ").ToModels();

                        foreach (var uitem in userModel)
                        {
                            var openid = uitem["user_xcxopenid"];
                            loginfo.Info(openid);
                            if (!string.IsNullOrWhiteSpace(openid))
                            {
                                //发送消息
                                WebServiceShopping.wechartTools.SendMsg(new WebServiceShopping.wechartTools.CheckInfo()
                                {

                                    page = $"/pages/orderCenter/orderCenter?tabindex=1&yonghuid={repair_yonghuid}",
                                    touser = openid,
                                    data = new WebServiceShopping.wechartTools.CheckInfo.DataModel()
                                    {
                                        thing10 = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = repair_companyname
                                        },
                                        thing3 = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = "检测结果已出"
                                        },

                                        time2 = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = DateTime.Now.ToString("yyyy年MM月dd HH:mm")
                                        },
                                        thing4 = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = $"请进入小程序确认检测结果。"
                                        }

                                    }
                                });
                            }
                        }
                    }
                    #endregion

                    mainsql.closesql();
                    tsall.Complete();
                    ret.Byte_Flag = (sbyte)1;
                }

            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                loginfo.Info(ex);
            }

        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }

        [WebMethod(Description = "修理厂发起询价")]//3-4-0
        public string Company_SureRepairXunjia(string msg)
        {
            ILog loginfo = LogManager.GetLogger("LoggerJieKou");

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Maplist_MapArgs = new Dictionary<string, List<Dictionary<string, string>>>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);

            mysqlcli mainsql = new mysqlcli();

            try
            {
                using (TransactionScope tsall = new TransactionScope())
                {
                    mainsql.openShopServicesql();

                    var repair_id = comrcv.Map_Args["repair_id"];
                    var user_id = comrcv.Map_Args["user_id"];
                    var content = comrcv.Map_Args["Content"];
                    var fileIds = comrcv.Map_Args["files"];
                    var ids = comrcv.Map_Args["carid"].Split(",".ToArray(), StringSplitOptions.RemoveEmptyEntries).ToArray();
                    var carid = string.Join(",", ids);
                    var products = comrcv.Map_Args["products"];
                    JArray json = JsonConvert.DeserializeObject<JArray>(products);
                    string productscount = json.Count.ToString();
                    string productsnames = "";
                    if (json != null && json.Count > 0)
                    {
                        foreach (var item in json)
                        {
                            productsnames += "【" + item.Value<string>("name") + "】";

                        }
                    }

                    #region 获取车辆价格信息

                    var proInfo = Helper.GetShichedao(content, json, loginfo);
                    products = string.IsNullOrWhiteSpace(proInfo) ? products : proInfo;

                    #endregion

                    var ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} WHERE repair_id ='{1}' ;", BIAOUSERREPAIR, repair_id));
                    if (ds.Rows.Count == 0)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "没有相关订单";
                        goto EXIT;
                    }
                    user_id = ds.Rows[0]["repair_yonghuid"].ToString();


                    string newxunjiaid = getxunjiaid(mainsql);

                    if (mainsql.SqlExcuteNoReturn($"insert into {BIAOXUNJIA + DateTime.Now.ToString("yyyyMM")}(user_id,repair_id,xj_id,x_content,x_img_ids,x_send_time,x_deleteflag,x_car_id,x_products,x_number) "
                         + $"values('{user_id}','{repair_id}','{newxunjiaid}','{content}','{fileIds}',NOW(),0,'{carid}',@product,0)", new MySqlParameter("@product", products)) != 1)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "服务器异常";
                        goto EXIT;
                    }

                    if (!string.IsNullOrWhiteSpace(fileIds))
                        ConvertTemporary(mainsql, fileIds);

                    string cmd = string.Format(" update {0} set repair_status1='3',repair_status2='4',repair_xunjiaid='{1}' where repair_id ='{2}' ;",
                        BIAOUSERREPAIR, newxunjiaid, repair_id);
                    int retint = mainsql.SqlExcuteNoReturn(cmd);
                    if (retint != 1)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "用户发起询价失败";
                        goto EXIT;
                    }




                    #region 发微信消息
                    var shopids = mainsql.SqlExcuteWithReturn($"select shop_id from {BIAOSHOPCAR} t1 where t1.car_type_id in ('{string.Join("','", ids)}') and t1.shop_car_deleteflag=0  group by shop_id").ToModels();


                    var userIds = new List<string>();
                    foreach (var item in shopids)
                    {
                        var shopId = item["shop_id"];
                        var users = mainsql.SqlExcuteWithReturn($"select t2.user_openid_juhesheng,t2.user_phone,t2.user_name,t2.user_onlyid from {BIAOSHOPUSER} t1 left join {BIAOUSER} t2 on t1.user_id=t2.user_onlyid where shop_id='{shopId}' and shop_user_ismsg=1 and shop_user_deleteflag<>1").ToModels();
                        foreach (var uitem in users)
                        {
                            var openid = uitem["user_openid_juhesheng"];
                            if (!string.IsNullOrWhiteSpace(openid))
                            {
                                userIds.Add(uitem["user_onlyid"]);
                                //发送消息
                                WebServiceShopping.wechartTools.SendMsgGZH(new WebServiceShopping.wechartTools.XunJiaMsg()
                                {
                                    miniprogram = new WebServiceShopping.wechartTools.XCXPath()
                                    {
                                        pagepath = "/pages/my/store/store?ShopId=" + shopId
                                    },
                                    touser = openid,
                                    data = new WebServiceShopping.wechartTools.XunJiaMsg.DataModel()
                                    {
                                        first = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = "您有新的询价单"
                                        },
                                        keyword2 = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = DateTime.Now.ToString("yyyy年MM月dd HH:mm")
                                        },
                                        keyword3 = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = productsnames
                                        },
                                        keyword1 = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = "合作修理厂"
                                        },
                                        keyword4 = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = productscount
                                        }
                                    }
                                });
                            }
                        }
                    }

                    var ps = mainsql.SqlExecuteScalar($"select c_name from {BIAOSHOPCONFIG} where c_type='xunjiamsg'")?.ToString();
                    if (!string.IsNullOrWhiteSpace(ps))
                    {
                        loginfo.Error(ps);
                        var ss = ps.Split(",".ToArray(), StringSplitOptions.RemoveEmptyEntries);
                        if (ss.Length > 0)
                        {
                            var users = mainsql.SqlExcuteWithReturn($"select user_openid_juhesheng,user_phone,user_name,user_onlyid from {BIAOUSER} where user_phone in ('{string.Join("','", ss)}')").ToModels();
                            foreach (var item in users)
                            {
                                if (!userIds.Contains(item["user_onlyid"]))
                                {
                                    var openid = item["user_openid_juhesheng"];
                                    loginfo.Error(openid);
                                    if (!string.IsNullOrWhiteSpace(openid))
                                    {
                                        //发送消息
                                        WebServiceShopping.wechartTools.SendMsgGZH(new WebServiceShopping.wechartTools.XunJiaMsg()
                                        {
                                            miniprogram = null,
                                            touser = openid,
                                            data = new WebServiceShopping.wechartTools.XunJiaMsg.DataModel()
                                            {
                                                first = new WebServiceShopping.wechartTools.DataItem()
                                                {
                                                    value = "您有新的询价单"
                                                },
                                                keyword2 = new WebServiceShopping.wechartTools.DataItem()
                                                {
                                                    value = DateTime.Now.ToString("yyyy年MM月dd HH:mm")
                                                },
                                                keyword3 = new WebServiceShopping.wechartTools.DataItem()
                                                {
                                                    value = productsnames
                                                },
                                                keyword1 = new WebServiceShopping.wechartTools.DataItem()
                                                {
                                                    value = "合作修理厂"
                                                },
                                                keyword4 = new WebServiceShopping.wechartTools.DataItem()
                                                {
                                                    value = productscount
                                                }
                                            }
                                        });
                                    }
                                }
                            }
                        }
                    }
                    #endregion




                    ret.Map_Args["ErrorMsg"] = "操作成功";
                    mainsql.closesql();
                    tsall.Complete();
                    ret.Byte_Flag = (sbyte)1;
                }
            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                loginfo.Info(ex);
            }

        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }

        [WebMethod(Description = "修理厂自己报价")]//3-4-1
        public string Company_SureRepairBaojia(string msg)
        {
            ILog loginfo = LogManager.GetLogger("LoggerJieKou");

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Maplist_MapArgs = new Dictionary<string, List<Dictionary<string, string>>>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);

            mysqlcli mainsql = new mysqlcli();

            try
            {
                using (TransactionScope tsall = new TransactionScope())
                {
                    mainsql.openShopServicesql();
                    var repair_id = comrcv.Map_Args["repair_id"];
                    var id = comrcv.Map_Args["x_id"];
                    var userid = comrcv.Map_Args["userid"];
                    var shopId = comrcv.Map_Args["ShopId"];     //修理厂的id
                    var price = comrcv.Map_Args["Price"];
                    var products = comrcv.Map_Args["products"];
                    var descript = comrcv.Map_Args["Descript"];
                    var time = comrcv.Map_Args["Time"];         //yyyy-MM 或者当前时间
                    time = time.ToDateTime().Value.ToString("yyyy-MM").Substring(0, 7) + "-01";
                    var fileIds = comrcv.Map_Args.ContainsKey("files") ? comrcv.Map_Args["files"] : string.Empty;


                    if (mainsql.SqlExcuteNoReturn($"insert into {BIAOBAOJIA + time.ToDateTime().Value.ToString("yyyyMM")}(x_id,shop_id,user_id,b_price,b_descript,b_products,b_img_ids,b_createtime,b_tuijianflag) values(@id,@shopid,@userid,@price,@descript,@product,@files,NOW(),0)"
                        , new MySqlParameter("@id", id), new MySqlParameter("@shopid", shopId), new MySqlParameter("@userid", userid), new MySqlParameter("@price", price), new MySqlParameter("@descript", descript), new MySqlParameter("@product", products), new MySqlParameter("@files", fileIds)) != 1)
                    {
                        ret.Map_Args["ErrorMsg"] = "操作失败";
                        mainsql.closesql();
                        goto EXIT;
                    }
                    mainsql.SqlExcuteNoReturn($"update {BIAOXUNJIA + time.ToDateTime().Value.ToString("yyyyMM")} set x_number=x_number+1 where x_id='{id}'");

                    //如果有附件图片，转成永久
                    if (!string.IsNullOrWhiteSpace(fileIds))
                        ConvertTemporary(mainsql, fileIds);


                    string updatestr = string.Format(" repair_status1='3',repair_status2='4',repair_status3='1' ");


                    string cmd = string.Format(" update {0} set {1} where repair_id ='{2}' ;", BIAOUSERREPAIR, updatestr, repair_id);
                    int retint = mainsql.SqlExcuteNoReturn(cmd);
                    if (retint != 1)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "修改状态失败";
                        goto EXIT;
                    }

                    ret.Map_Args["ErrorMsg"] = "操作成功";
                    mainsql.closesql();
                    tsall.Complete();
                    ret.Byte_Flag = (sbyte)1;
                }
            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                loginfo.Info(ex);
            }
        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }

        [WebMethod(Description = "修理厂修改自己报价")]//3-4-1
        public string Company_SureRepairChangeBaojia(string msg)
        {
            ILog loginfo = LogManager.GetLogger("LoggerJieKou");

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Maplist_MapArgs = new Dictionary<string, List<Dictionary<string, string>>>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);

            mysqlcli mainsql = new mysqlcli();

            try
            {
                using (TransactionScope tsall = new TransactionScope())
                {
                    mainsql.openShopServicesql();
                    var repair_id = comrcv.Map_Args["repair_id"];
                    var x_id = comrcv.Map_Args["x_id"];
                    var shopId = comrcv.Map_Args["ShopId"];//修理厂的id
                    var price = comrcv.Map_Args["Price"];
                    var products = comrcv.Map_Args["products"];
                    var descript = comrcv.Map_Args["Descript"];
                    var time = comrcv.Map_Args["Time"];//yyyy-MM 或者当前时间
                    time = time.ToDateTime().Value.ToString("yyyy-MM").Substring(0, 7) + "-01";
                    var fileIds = comrcv.Map_Args.ContainsKey("files") ? comrcv.Map_Args["files"] : string.Empty;



                    if (mainsql.SqlExcuteNoReturn($"update {BIAOBAOJIA + time.ToDateTime().Value.ToString("yyyyMM")} set b_price=@price,b_descript=@descript,b_products=@product,b_img_ids=@files,b_createtime=NOW() where shop_id=@shopId and x_id=@x_id"
                      , new MySqlParameter("@price", price), new MySqlParameter("@shopId", shopId), new MySqlParameter("@x_id", x_id), new MySqlParameter("@descript", descript), new MySqlParameter("@product", products), new MySqlParameter("@files", fileIds)) != 1)
                    {
                        ret.Map_Args["ErrorMsg"] = "操作失败";
                        mainsql.closesql();
                        goto EXIT;
                    }


                    //如果有附件图片，转成永久
                    if (!string.IsNullOrWhiteSpace(fileIds))
                        ConvertTemporary(mainsql, fileIds);



                    ret.Map_Args["ErrorMsg"] = "操作成功";
                    mainsql.closesql();
                    tsall.Complete();
                    ret.Byte_Flag = (sbyte)1;
                }
            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                loginfo.Info(ex);
            }

        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }

        [WebMethod(Description = "修理厂获取自己报价")]
        public string Company_SureRepairGetBaojia(string msg)
        {
            ILog loginfo = LogManager.GetLogger("LoggerJieKou");

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Maplist_MapArgs = new Dictionary<string, List<Dictionary<string, string>>>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);

            mysqlcli mainsql = new mysqlcli();

            try
            {
                using (TransactionScope tsall = new TransactionScope())
                {
                    mainsql.openShopServicesql();
                    var repair_id = comrcv.Map_Args["repair_id"];
                    var company_id = comrcv.Map_Args["company_id"];

                    var ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} WHERE repair_id ='{1}' ;", BIAOUSERREPAIR, repair_id));
                    if (ds.Rows.Count == 0)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "没有相关订单";
                        goto EXIT;
                    }
                    string xjid = ds.Rows[0]["repair_xunjiaid"].ToString();

                    string yymm = xjid.Substring(0, 6);

                    ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} WHERE x_id ='{1}' and shop_id='{2}' ;", BIAOBAOJIA + yymm, xjid, company_id));
                    if (ds.Rows.Count == 0)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "没有询价订单";
                        goto EXIT;
                    }
                    ret.Maplist_MapArgs = new Dictionary<string, List<Dictionary<string, string>>>();
                    var lis = ds.ToModels();

                    ret.Maplist_MapArgs.Add("Datas", lis);




                    ret.Map_Args["ErrorMsg"] = "操作成功";
                    mainsql.closesql();
                    tsall.Complete();
                    ret.Byte_Flag = (sbyte)1;
                }
            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                loginfo.Info(ex);
            }

        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }

        [WebMethod(Description = "根据维修订单获取询价单")]
        public string All_GetRepairXunjia(string msg)
        {
            ILog loginfo = LogManager.GetLogger("LoggerJieKou");

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Maplist_MapArgs = new Dictionary<string, List<Dictionary<string, string>>>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);

            mysqlcli mainsql = new mysqlcli();

            try
            {
                using (TransactionScope tsall = new TransactionScope())
                {
                    mainsql.openShopServicesql();
                    var repair_id = comrcv.Map_Args["repair_id"];


                    var ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} WHERE repair_id ='{1}' ;", BIAOUSERREPAIR, repair_id));
                    if (ds.Rows.Count == 0)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "没有相关订单";
                        goto EXIT;
                    }
                    string xjid = ds.Rows[0]["repair_xunjiaid"].ToString();

                    string yymm = xjid.Substring(0, 6);

                    ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} WHERE xj_id ='{1}' ;", BIAOXUNJIA + yymm, xjid));
                    if (ds.Rows.Count == 0)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "没有询价订单";
                        goto EXIT;
                    }
                    ret.Maplist_MapArgs = new Dictionary<string, List<Dictionary<string, string>>>();
                    var lis = ds.ToModels();

                    ret.Maplist_MapArgs.Add("Datas", lis);




                    ret.Map_Args["ErrorMsg"] = "操作成功";
                    mainsql.closesql();
                    tsall.Complete();
                    ret.Byte_Flag = (sbyte)1;
                }
            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                loginfo.Info(ex);
            }

        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }

        //b_tuijianflag
        [WebMethod(Description = "修理厂推荐报价")]
        public string Company_RepairTuiJianBaojia(string msg)
        {
            ILog loginfo = LogManager.GetLogger("LoggerJieKou");

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Maplist_MapArgs = new Dictionary<string, List<Dictionary<string, string>>>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);

            mysqlcli mainsql = new mysqlcli();

            try
            {
                using (TransactionScope tsall = new TransactionScope())
                {
                    mainsql.openShopServicesql();
                    var repair_id = comrcv.Map_Args["repair_id"];   //维修单ID
                    var b_id = comrcv.Map_Args["b_id"];             //报价ID

                    var ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} WHERE repair_id ='{1}' ;", BIAOUSERREPAIR, repair_id));
                    if (ds.Rows.Count == 0)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "没有相关订单";
                        goto EXIT;
                    }
                    string xjid = ds.Rows[0]["repair_xunjiaid"].ToString();


                    string repair_yonghuid = ds.Rows[0]["repair_yonghuid"].ToString();
                    string repair_companyname = ds.Rows[0]["repair_companyname"].ToString();
                    string repair_carplate = ds.Rows[0]["repair_carplate"].ToString();


                    string yymm = xjid.Substring(0, 6);


                    string cmd = string.Format(" update {0} set b_tuijianflag='1' where b_id ='{1}' ;",
                        BIAOBAOJIA + yymm, b_id);
                    int retint = mainsql.SqlExcuteNoReturn(cmd);
                    if (retint != 1)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "修理厂不能推荐自己的报价";
                        goto EXIT;
                    }

                    #region 发微信消息
                    {

                        var userModel = mainsql.SqlExcuteWithReturn($"select user_xcxopenid from {BIAOUSER} where user_onlyid IN ('{repair_yonghuid}')  ").ToModels();

                        foreach (var uitem in userModel)
                        {
                            var openid = uitem["user_xcxopenid"];
                            loginfo.Info(openid);
                            if (!string.IsNullOrWhiteSpace(openid))
                            {
                                //发送消息
                                WebServiceShopping.wechartTools.SendMsg(new WebServiceShopping.wechartTools.JieSuanInfo()
                                {

                                    page = $"/pages/orderCenter/orderCenter?tabindex=1&yonghuid={repair_yonghuid}",
                                    touser = openid,
                                    data = new WebServiceShopping.wechartTools.JieSuanInfo.DataModel()
                                    {
                                        phrase3 = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = "待支付"
                                        },
                                        character_string1 = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = repair_id
                                        },

                                        car_number2 = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = repair_carplate
                                        },
                                        amount4 = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = "0"
                                        },
                                        thing5 = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = $"请及时选择报价并支付。"
                                        }

                                    }
                                });
                            }
                        }
                    }
                    #endregion

                    ret.Map_Args["ErrorMsg"] = "操作成功";
                    mainsql.closesql();
                    tsall.Complete();
                    ret.Byte_Flag = (sbyte)1;
                }
            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                loginfo.Info(ex);
            }

        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }

        [WebMethod(Description = "修理厂确认开始维修")]//3-6-0
        public string Company_SureRepairing(string msg)
        {
            ILog loginfo = LogManager.GetLogger("LoggerJieKou");

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);
            mysqlcli mainsql = new mysqlcli();

            try
            {
                var repair_id = comrcv.Map_Args["repair_id"];


                var repair_hours = comrcv.Map_Args.ContainsKey("repair_hours") ? comrcv.Map_Args["repair_hours"] : "2";//传小时

                var repair_repairpic_ids = comrcv.Map_Args.ContainsKey("repair_repairpic_ids") ? comrcv.Map_Args["repair_repairpic_ids"] : "";

                int inthours = 2;
                int.TryParse(repair_hours, out inthours);

                string repair_overtime = DateTime.Now.AddHours(inthours).ToString("yyyy-MM-dd HH:mm:ss");

                loginfo.Info("修理厂确认开始维修--" + repair_id);
                using (TransactionScope tsall = new TransactionScope())
                {
                    mainsql.openShopServicesql();
                    string sqlwhere = string.Format("WHERE repair_id ='{0}' ", repair_id);

                    var ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} {1};", BIAOUSERREPAIR, sqlwhere));
                    if (ds.Rows.Count == 0)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "没有相关订单";
                        goto EXIT;
                    }

                    string updatestr = string.Format(" repair_status1='3',repair_status2='6',repair_status3='0' ");

                    updatestr += string.Format(" ,repair_overtime='{0}' ", repair_overtime);

                    if (repair_repairpic_ids != "")
                    {
                        updatestr += string.Format(" ,repair_repairpic_ids='{0}' ", repair_repairpic_ids);
                    }

                    string cmd = string.Format(" update {0} set {1} where repair_id ='{2}' ;", BIAOUSERREPAIR, updatestr, repair_id);
                    int retint = mainsql.SqlExcuteNoReturn(cmd);
                    if (retint != 1)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "修理厂确认开始维修失败";
                        goto EXIT;
                    }

                    if (!string.IsNullOrWhiteSpace(repair_repairpic_ids))
                        ConvertTemporary(mainsql, repair_repairpic_ids);


                    mainsql.closesql();
                    tsall.Complete();
                    ret.Byte_Flag = (sbyte)1;
                }

            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                loginfo.Info(ex);
            }

        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }

        [WebMethod(Description = "修理厂确认维修结束")]//4-2-0
        public string Company_SureRepairend(string msg)
        {
            ILog loginfo = LogManager.GetLogger("LoggerJieKou");

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);
            mysqlcli mainsql = new mysqlcli();

            try
            {
                var repair_id = comrcv.Map_Args["repair_id"];



                loginfo.Info("修理厂确认维修结束--" + repair_id);
                using (TransactionScope tsall = new TransactionScope())
                {
                    mainsql.openShopServicesql();
                    string sqlwhere = string.Format("WHERE repair_id ='{0}' AND  repair_status1='3' AND repair_status2='6' AND repair_status3='0'  ", repair_id);

                    var ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} {1};", BIAOUSERREPAIR, sqlwhere));
                    if (ds.Rows.Count == 0)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "没有相关订单或者状态不对";
                        goto EXIT;
                    }

                    string repair_yonghuid = ds.Rows[0]["repair_yonghuid"].ToString();
                    string repair_companyname = ds.Rows[0]["repair_companyname"].ToString();
                    string repair_carplate = ds.Rows[0]["repair_carplate"].ToString();
                    string repair_yonghuname = ds.Rows[0]["repair_yonghuname"].ToString();
                    string updatestr = string.Format(" repair_status1='4',repair_status2='2',repair_status3='0' ");




                    string cmd = string.Format(" update {0} set {1} where repair_id ='{2}' ;", BIAOUSERREPAIR, updatestr, repair_id);
                    int retint = mainsql.SqlExcuteNoReturn(cmd);
                    if (retint != 1)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "修理厂确认开始维修失败";
                        goto EXIT;
                    }

                    #region 发微信消息
                    {

                        var userModel = mainsql.SqlExcuteWithReturn($"select user_xcxopenid from {BIAOUSER} where user_onlyid IN ('{repair_yonghuid}')  ").ToModels();

                        foreach (var uitem in userModel)
                        {
                            var openid = uitem["user_xcxopenid"];
                            loginfo.Info(openid);
                            if (!string.IsNullOrWhiteSpace(openid))
                            {
                                //发送消息
                                WebServiceShopping.wechartTools.SendMsg(new WebServiceShopping.wechartTools.JiaoCheInfo()
                                {

                                    page = $"/pages/orderCenter/orderCenter?tabindex=1&yonghuid={repair_yonghuid}",
                                    touser = openid,
                                    data = new WebServiceShopping.wechartTools.JiaoCheInfo.DataModel()
                                    {
                                        date3 = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = DateTime.Now.ToString("yyyy年MM月dd HH:mm")
                                        },
                                        thing9 = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = $"您的爱车【{repair_carplate}】已经维护完毕"
                                        },

                                        character_string2 = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = repair_id
                                        },
                                        name5 = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = repair_companyname
                                        },
                                        thing7 = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = $"车辆已经维护检测完毕，请放心使用。"
                                        }

                                    }
                                });
                            }
                        }
                    }
                    #endregion

                    mainsql.closesql();
                    tsall.Complete();
                    ret.Byte_Flag = (sbyte)1;
                }

            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                loginfo.Info(ex);
            }

        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }

        [WebMethod(Description = "修理厂确认送车")]//4-1-0
        public string Company_Songcheing(string msg)
        {
            ILog loginfo = LogManager.GetLogger("LoggerJieKou");

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);
            mysqlcli mainsql = new mysqlcli();

            try
            {
                var repair_id = comrcv.Map_Args["repair_id"];



                loginfo.Info("修理厂确认送车--" + repair_id);
                using (TransactionScope tsall = new TransactionScope())
                {
                    mainsql.openShopServicesql();
                    string sqlwhere = string.Format("WHERE repair_id ='{0}' ", repair_id);

                    var ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} {1};", BIAOUSERREPAIR, sqlwhere));
                    if (ds.Rows.Count == 0)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "没有相关订单";
                        goto EXIT;
                    }

                    string updatestr = string.Format(" repair_status1='4',repair_status2='1',repair_status3='0' ");


                    string cmd = string.Format(" update {0} set {1} where repair_id ='{2}' ;", BIAOUSERREPAIR, updatestr, repair_id);
                    int retint = mainsql.SqlExcuteNoReturn(cmd);
                    if (retint != 1)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "修理厂确认交车失败";
                        goto EXIT;
                    }



                    mainsql.closesql();
                    tsall.Complete();
                    ret.Byte_Flag = (sbyte)1;
                }

            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                loginfo.Info(ex);
            }

        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }

        [WebMethod(Description = "修理厂确认交车")]//4-2-0
        public string Company_SureRepairBackcar(string msg)
        {
            ILog loginfo = LogManager.GetLogger("LoggerJieKou");

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);
            mysqlcli mainsql = new mysqlcli();

            try
            {
                var repair_id = comrcv.Map_Args["repair_id"];



                loginfo.Info("修理厂确认交车--" + repair_id);
                using (TransactionScope tsall = new TransactionScope())
                {
                    mainsql.openShopServicesql();
                    string sqlwhere = string.Format("WHERE repair_id ='{0}' ", repair_id);

                    var ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} {1};", BIAOUSERREPAIR, sqlwhere));
                    if (ds.Rows.Count == 0)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "没有相关订单";
                        goto EXIT;
                    }



                    string repair_yonghuid = ds.Rows[0]["repair_yonghuid"].ToString();
                    string repair_companyname = ds.Rows[0]["repair_companyname"].ToString();
                    string repair_carplate = ds.Rows[0]["repair_carplate"].ToString();

                    string repair_yonghuname = ds.Rows[0]["repair_yonghuname"].ToString();

                    string updatestr = string.Format(" repair_status1='4',repair_status2='2',repair_status3='0' ");
                    string cmd = string.Format(" update {0} set {1} where repair_id ='{2}' ;", BIAOUSERREPAIR, updatestr, repair_id);
                    int retint = mainsql.SqlExcuteNoReturn(cmd);
                    if (retint != 1)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "修理厂确认交车失败";
                        goto EXIT;
                    }

                    #region 发微信消息
                    {

                        var userModel = mainsql.SqlExcuteWithReturn($"select user_xcxopenid from {BIAOUSER} where user_onlyid IN ('{repair_yonghuid}')  ").ToModels();

                        foreach (var uitem in userModel)
                        {
                            var openid = uitem["user_xcxopenid"];
                            loginfo.Info(openid);
                            if (!string.IsNullOrWhiteSpace(openid))
                            {
                                //发送消息
                                WebServiceShopping.wechartTools.SendMsg(new WebServiceShopping.wechartTools.JiaoCheInfo()
                                {

                                    page = $"/pages/orderCenter/orderCenter?tabindex=1&yonghuid={repair_yonghuid}",
                                    touser = openid,
                                    data = new WebServiceShopping.wechartTools.JiaoCheInfo.DataModel()
                                    {
                                        date3 = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = DateTime.Now.ToString("yyyy年MM月dd HH:mm")
                                        },
                                        thing9 = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = $"您的爱车【{repair_carplate}】已经维护完毕"
                                        },

                                        character_string2 = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = repair_id
                                        },
                                        name5 = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = repair_companyname
                                        },
                                        thing7 = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = $"车辆已经维护检测完毕，请放心使用。"
                                        }

                                    }
                                });
                            }
                        }
                    }
                    #endregion


                    mainsql.closesql();
                    tsall.Complete();
                    ret.Byte_Flag = (sbyte)1;
                }

            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                loginfo.Info(ex);
            }

        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }

        [WebMethod(Description = "修理厂修改工时和材料信息")]//3-3-0
        public string Company_ChangeRepairlist(string msg)
        {
            ILog loginfo = LogManager.GetLogger("LoggerJieKou");

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);
            mysqlcli mainsql = new mysqlcli();
            mainsql.openShopServicesql();
            try
            {
                var repair_id = comrcv.Map_Args["repair_id"];

                var repair_repairinfo = comrcv.Map_Args["repair_repairinfo"];//维修类容json
                var repair_repairinfo_products = comrcv.Map_Args["repair_repairinfo_products"];//维修材料json
                string repair_gongshiprice = comrcv.Map_Args["repair_gongshiprice"];//工时费用，没有传0

                using (TransactionScope tsall = new TransactionScope())
                {

                    string sqlwhere = string.Format("WHERE repair_id ='{0}' ", repair_id);

                    var ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} {1};", BIAOUSERREPAIR, sqlwhere));
                    if (ds.Rows.Count == 0)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "没有相关订单";
                        goto EXIT;
                    }
                    string repair_companyid = ds.Rows[0]["repair_companyid"].ToString();
                    string repair_carplate = ds.Rows[0]["repair_carplate"].ToString();

                    string repair_yonghuname = ds.Rows[0]["repair_yonghuname"].ToString();


                    double serviceprice = 0, allprice = 0, gongshiprice = 0, productprice = 0;
                    serviceprice = ds.Rows[0]["repair_serviceprice"].ToDouble();

                    productprice = ds.Rows[0]["repair_productprice"].ToDouble();

                    double.TryParse(repair_gongshiprice, out gongshiprice);
                    allprice = serviceprice + gongshiprice + productprice;

                    string updatestr = string.Format(" repair_repairinfo='{0}' ", repair_repairinfo);
                    updatestr += string.Format(" ,repair_repairinfo_products='{0}' ", repair_repairinfo_products);
                    updatestr += string.Format(" ,repair_gongshiprice='{0}' ", repair_gongshiprice);
                    updatestr += string.Format(" ,repair_allprice='{0}' ", allprice);

                    updatestr += string.Format(" ,repair_status1='3',repair_status2='2',repair_status3='0' ");

                    string cmd = string.Format(" update {0} set {1} where repair_id ='{2}' ;", BIAOUSERREPAIR, updatestr, repair_id);
                    int retint = mainsql.SqlExcuteNoReturn(cmd);
                    if (retint != 1)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "修改订单失败";
                        goto EXIT;
                    }

                    mainsql.closesql();
                    tsall.Complete();
                    ret.Byte_Flag = (sbyte)1;
                }

            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                loginfo.Info(ex);
            }

        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }

        [WebMethod(Description = "修理厂修改工时和服务信息")]
        public string Company_ChangeServiceProduct(string msg)
        {
            ILog loginfo = LogManager.GetLogger("LoggerJieKou");

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);
            mysqlcli mainsql = new mysqlcli();
            mainsql.openShopServicesql();
            try
            {
                var repair_id = comrcv.Map_Args["repair_id"];

                var repair_repairinfo = comrcv.Map_Args["repair_repairinfo"];//维修类容json
                var repair_repairinfo_products = comrcv.Map_Args["repair_repairinfo_products"];//维修材料json

                var repair_service = comrcv.Map_Args["repair_service"];//服务项目000
                var repair_serviceprice = comrcv.Map_Args["repair_serviceprice"];//服务总费用

                string repair_gongshiprice = comrcv.Map_Args["repair_gongshiprice"];//工时费用，没有传0

                using (TransactionScope tsall = new TransactionScope())
                {

                    string sqlwhere = string.Format("WHERE repair_id ='{0}' ", repair_id);

                    var ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} {1};", BIAOUSERREPAIR, sqlwhere));
                    if (ds.Rows.Count == 0)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "没有相关订单";
                        goto EXIT;
                    }
                    string repair_companyid = ds.Rows[0]["repair_companyid"].ToString();
                    string repair_carplate = ds.Rows[0]["repair_carplate"].ToString();
                    string repair_yonghuname = ds.Rows[0]["repair_yonghuname"].ToString();


                    double serviceprice = 0, allprice = 0, gongshiprice = 0, productprice = 0;
                    //serviceprice = ds.Rows[0]["repair_serviceprice"].ToDouble();
                    //gongshiprice = ds.Rows[0]["repair_gongshiprice"].ToDouble();
                    productprice = ds.Rows[0]["repair_productprice"].ToDouble();
                    double.TryParse(repair_gongshiprice, out gongshiprice);
                    double.TryParse(repair_serviceprice, out serviceprice);


                    allprice = serviceprice + gongshiprice + productprice;

                    string updatestr = string.Format(" repair_repairinfo='{0}' ", repair_repairinfo);
                    updatestr += string.Format(" ,repair_repairinfo_products='{0}' ", repair_repairinfo_products);
                    updatestr += string.Format(" ,repair_gongshiprice='{0}' ", repair_gongshiprice);
                    updatestr += string.Format(" ,repair_serviceprice='{0}' ", repair_serviceprice);
                    updatestr += string.Format(" ,repair_service='{0}' ", repair_service);
                    updatestr += string.Format(" ,repair_allprice='{0}' ", allprice);



                    string cmd = string.Format(" update {0} set {1} where repair_id ='{2}' ;", BIAOUSERREPAIR, updatestr, repair_id);
                    int retint = mainsql.SqlExcuteNoReturn(cmd);
                    if (retint != 1)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "修改订单失败";
                        goto EXIT;
                    }

                    mainsql.closesql();
                    tsall.Complete();
                    ret.Byte_Flag = (sbyte)1;
                }

            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                loginfo.Info(ex);
            }

        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }

        #endregion

        #region 商家流程

        [WebMethod(Description = "商户确认发货")]//3-5-2
        public string ShangHu_SureFaHuo(string msg)
        {
            ILog loginfo = LogManager.GetLogger("LoggerJieKou");

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);
            mysqlcli mainsql = new mysqlcli();

            try
            {
                var repair_id = comrcv.Map_Args["repair_id"];
                var repair_default = comrcv.Map_Args["repair_default"];

                loginfo.Info("修理厂确认开始维修--" + repair_id);
                using (TransactionScope tsall = new TransactionScope())
                {
                    mainsql.openShopServicesql();
                    string sqlwhere = string.Format("WHERE repair_id ='{0}' ", repair_id);

                    var ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} {1};", BIAOUSERREPAIR, sqlwhere));
                    if (ds.Rows.Count == 0)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "没有相关订单";
                        goto EXIT;
                    }
                    string repair_carplate = ds.Rows[0]["repair_carplate"].ToString();
                    string repair_yonghuname = ds.Rows[0]["repair_yonghuname"].ToString();
                    string repair_companyid = ds.Rows[0]["repair_companyid"].ToString();
                    string repair_companyname = ds.Rows[0]["repair_companyname"].ToString();
                    string repair_allprice = ds.Rows[0]["repair_allprice"].ToString();
                    string updatestr = string.Format(" repair_status1='3',repair_status2='5',repair_status3='2' ");

                    updatestr += string.Format(" ,repair_default='{0}'", repair_default);


                    string cmd = string.Format(" update {0} set {1} where repair_id ='{2}' ;", BIAOUSERREPAIR, updatestr, repair_id);
                    int retint = mainsql.SqlExcuteNoReturn(cmd);
                    if (retint != 1)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "修理厂确认开始维修失败";
                        goto EXIT;
                    }

                    #region 发微信消息
                    {


                        var user_binduserid = mainsql.SqlExecuteScalar($"select user_binduserid from {BIAOUSERCOMPANY} where user_id='{repair_companyid}'").ToString();
                        var ids = user_binduserid.Split(",".ToArray(), StringSplitOptions.RemoveEmptyEntries);
                        var user_onlyids = string.Join("','", ids);
                        var userModel = mainsql.SqlExcuteWithReturn($"select user_openid_juhesheng from {BIAOUSER} where user_phone IN ('{user_onlyids}')  ").ToModels();

                        foreach (var uitem in userModel)
                        {
                            var openid = uitem["user_openid_juhesheng"];
                            loginfo.Info("获取open:" + openid);
                            if (!string.IsNullOrWhiteSpace(openid))
                            {
                                //发送消息
                                WebServiceShopping.wechartTools.SendMsgGZH(new WebServiceShopping.wechartTools.FaHuoMsg()
                                {
                                    miniprogram = new WebServiceShopping.wechartTools.XCXPath()
                                    {
                                        pagepath = $"/pages/my/repairfactory/index/index?companyid={repair_companyid}"
                                    },
                                    touser = openid,
                                    data = new WebServiceShopping.wechartTools.FaHuoMsg.DataModel()
                                    {
                                        first = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = $"您的订单已经发货！"
                                        },

                                        keyword1 = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = repair_id
                                        },
                                        keyword2 = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = repair_allprice
                                        },
                                        keyword3 = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = $"【{repair_yonghuname}】-({repair_carplate})"
                                        },
                                        keyword4 = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = repair_companyname
                                        },
                                        keyword5 = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = DateTime.Now.ToString("yyyy年MM月dd HH:mm")
                                        },
                                        remark = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = $"您的维修单已经发货，请及时处理！"
                                        },
                                    }
                                });
                            }
                        }
                    }
                    #endregion

                    mainsql.closesql();
                    tsall.Complete();
                    ret.Byte_Flag = (sbyte)1;
                }

            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                loginfo.Info(ex);
            }

        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }

        #endregion

        #endregion

        #region 评价

        [WebMethod(Description = "用户确认评价")]//6-0-0
        public string Yonghu_SureRepairPingjia(string msg)
        {
            ILog loginfo = LogManager.GetLogger("LoggerJieKou");

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);
            mysqlcli mainsql = new mysqlcli();

            try
            {
                var repair_id = comrcv.Map_Args["repair_id"];
                var repair_shopstar = comrcv.Map_Args["repair_shopstar"];//商家评分
                var repair_companystar = comrcv.Map_Args["repair_companystar"];//修理厂评分

                var repair_shopdefalut = comrcv.Map_Args["repair_shopdefalut"];//备注内容
                var repair_companydefalut = comrcv.Map_Args["repair_companydefalut"];//备注内容

                loginfo.Info("用户确认评价--" + repair_id);
                using (TransactionScope tsall = new TransactionScope())
                {
                    mainsql.openShopServicesql();
                    string sqlwhere = string.Format("WHERE repair_id ='{0}' AND repair_status1='5' ", repair_id);

                    var ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} {1};", BIAOUSERREPAIR, sqlwhere));
                    if (ds.Rows.Count == 0)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "没有相关订单";
                        goto EXIT;
                    }

                    string repair_orderprice = ds.Rows[0]["repair_allprice"].ToString();
                    double repair_productprice = ds.Rows[0]["repair_productprice"].ToDouble();
                    double repair_serviceprice = ds.Rows[0]["repair_serviceprice"].ToDouble();
                    double repair_gongshiprice = ds.Rows[0]["repair_gongshiprice"].ToDouble();

                    string repair_username = ds.Rows[0]["repair_yonghuname"].ToString();
                    string repair_userphone = ds.Rows[0]["repair_yonghuphone"].ToString();
                    string repair_companyid = ds.Rows[0]["repair_companyid"].ToString();
                    string repair_companyname = ds.Rows[0]["repair_companyname"].ToString();
                    string repair_shopid = ds.Rows[0]["repair_shopid"].ToString();
                    string repair_yonghuid = ds.Rows[0]["repair_yonghuid"].ToString();
                    string repair_carplate = ds.Rows[0]["repair_carplate"].ToString();
                    string repair_repairinfo_products = ds.Rows[0]["repair_repairinfo_products"].ToString();


                    string updatestr = string.Format(" repair_status1='6',repair_status2='1',repair_status3='1' ");


                    string cmd = string.Format(" update {0} set {1} where repair_id ='{2}' ;", BIAOUSERREPAIR, updatestr, repair_id);
                    int retint = mainsql.SqlExcuteNoReturn(cmd);
                    if (retint != 1)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "用户确认评价失败";
                        goto EXIT;
                    }

                    string intsertkeystr = SQLCOMPANYREPAIR;
                    string intsertvaluestr = SQLCOMPANYREPAIR;
                    intsertvaluestr = intsertvaluestr.Replace("repair_createtime", "'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'");//
                    intsertvaluestr = intsertvaluestr.Replace("repair_repairid", "'" + repair_id + "'");//
                    intsertvaluestr = intsertvaluestr.Replace("repair_orderprice", "'" + repair_orderprice + "'");//
                    intsertvaluestr = intsertvaluestr.Replace("repair_userid", "'" + repair_yonghuid + "'");//
                    intsertvaluestr = intsertvaluestr.Replace("repair_username", "'" + repair_username + "'");//
                    intsertvaluestr = intsertvaluestr.Replace("repair_userphone", "'" + repair_userphone + "'");//
                    intsertvaluestr = intsertvaluestr.Replace("repair_companyid", "'" + repair_companyid + "'");//
                    intsertvaluestr = intsertvaluestr.Replace("repair_companyname", "'" + repair_companyname + "'");//
                    intsertvaluestr = intsertvaluestr.Replace("repair_companystar", "'" + repair_companystar + "'");//
                    intsertvaluestr = intsertvaluestr.Replace("repair_shopid", "'" + repair_shopid + "'");//
                    intsertvaluestr = intsertvaluestr.Replace("repair_shopstar", "'" + repair_shopstar + "'");//
                    intsertvaluestr = intsertvaluestr.Replace("repair_companydefalut", "'" + repair_companydefalut + "'");//
                    intsertvaluestr = intsertvaluestr.Replace("repair_shopdefalut", "'" + repair_shopdefalut + "'");//
                    cmd = string.Format("insert into {0} ({1}) values ({2}) ", BIAOCOMPANYREPAIR, intsertkeystr, intsertvaluestr);
                    retint = mainsql.SqlExcuteNoReturn(cmd);
                    if (retint != 1)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "新增评价记录失败";
                        goto EXIT;
                    }
                    sqlwhere = string.Format(" select * from {0} WHERE user_id ='{1}' ", BIAOUSERCOMPANY, repair_companyid);
                    ds = mainsql.SqlExcuteWithReturn(sqlwhere);
                    if (ds.Rows.Count == 0)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "没有相关店铺";
                        goto EXIT;
                    }
                    int pingjiacount = ds.Rows[0]["user_pingjiacount"].ToInt32();
                    double oldpingjia = ds.Rows[0]["user_star"].ToInt32();
                    double allstar = oldpingjia * pingjiacount;
                    allstar = allstar + Convert.ToDouble(repair_companystar);

                    pingjiacount++;
                    allstar = allstar / pingjiacount;
                    cmd = string.Format(" update {0} set user_star='{1}',user_pingjiacount='{2}' where user_id ='{3}' ;", BIAOUSERCOMPANY, allstar, pingjiacount, repair_companyid);
                    retint = mainsql.SqlExcuteNoReturn(cmd);
                    if (retint != 1)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "修改店铺评价内容失败";
                        goto EXIT;
                    }

                    if (repair_companyid == repair_shopid)
                    {
                        #region 修理厂自己销售
                        sqlwhere = string.Format("WHERE user_id ='{0}' ", repair_companyid);
                        ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} {1};", BIAOUSERCOMPANY, sqlwhere));
                        if (ds.Rows.Count == 0)
                        {
                            mainsql.closesql();
                            ret.Map_Args["ErrorMsg"] = "没有相关站点";
                            goto EXIT;
                        }

                        double config_companyrepairbili = ds.Rows[0]["user_salerate"].ToDouble(); ;
                        double companyprice = 0, cailiaocompanyprice = 0;
                        cailiaocompanyprice = (repair_productprice * config_companyrepairbili);
                        companyprice = cailiaocompanyprice + repair_serviceprice + repair_gongshiprice;
                        companyprice = Math.Round(companyprice, 2);
                        cmd = string.Format(" update {0} set repair_status2='1' where repair_id ='{1}' ;", BIAOUSERREPAIR, repair_id);
                        retint = mainsql.SqlExcuteNoReturn(cmd);
                        if (retint != 1)
                        {
                            mainsql.closesql();
                            ret.Map_Args["ErrorMsg"] = "修改订单状态失败";
                            goto EXIT;
                        }

                        cmd = string.Format(" update {0} set user_price=user_price+{1} where user_id ='{2}' ;",
                            BIAOUSERCOMPANY, companyprice, repair_companyid);
                        retint = mainsql.SqlExcuteNoReturn(cmd);
                        if (retint != 1)
                        {
                            mainsql.closesql();
                            ret.Map_Args["ErrorMsg"] = "修改修理厂零钱失败";
                            goto EXIT;
                        }


                        //生成青贯流水号

                        string qgliushuinumber = GetLdpLiushui(mainsql);



                        cmd = string.Format("INSERT INTO {0} (zf_time,zf_type,zf_status,zf_qgnumber,zf_chnumber,zf_companyaccount," +
                        "zf_companynumber,zf_companyname,zf_companyamount,zf_companyrealtimebalance,zf_default,zf_zfphone,zf_way,zf_shouzhi,zf_comshouzhi,zf_biaoid)" +
                        " VALUES ('{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','提款','2','1','{13}')",
                        BIAOQGZHIFURECORD + DateTime.Now.ToString("yyyyMM"), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                        "修理厂分维修款", "支付成功", qgliushuinumber,
                        "", repair_companyid, "", repair_companyname, companyprice.ToString("0.00"),
                        companyprice.ToString("0.00"), "修理厂分维修款", "", repair_id);

                        retint = mainsql.SqlExcuteNoReturn(cmd);
                        if (retint != 1)
                        {
                            mainsql.closesql();
                            ret.Map_Args["ErrorMsg"] = "插入记录失败";
                            goto EXIT;
                        }
                        #endregion
                    }
                    else
                    {
                        #region 商家分钱

                        string qgliushuinumber = "";
                        if (repair_repairinfo_products != "")
                        {

                            //分钱
                            Dictionary<string, double> allshopprice = new Dictionary<string, double>();
                            JArray ja = JArray.Parse(repair_repairinfo_products);
                            for (int i = 0; i < ja.Count; i++)
                            {
                                JObject jo = JObject.Parse(ja[i].ToString());
                                string cpname = jo["Name"].ToString();
                                string shopid = jo["shopid"].ToString();
                                double price = jo["price"].ToDouble();
                                int Number = jo["Number"].ToInt32();

                                price = price * Number;
                                if (allshopprice.ContainsKey(shopid) == false)
                                {
                                    allshopprice.Add(shopid, price);
                                }
                                else
                                {
                                    allshopprice[shopid] += price;
                                }
                            }
                            foreach (var kvp in allshopprice)//遍历所有的店铺
                            {

                                string shopid = kvp.Key;

                                if (shopid == repair_companyid)
                                    continue;

                                double price = kvp.Value;
                                var shop_addrate = mainsql.SqlExecuteScalar($"select shop_addrate from {BIAOSHOP} where shop_id='{shopid}'").ToDouble();
                                price = price * (1 / shop_addrate);
                                price = Math.Round(price, 2);

                                cmd = string.Format($"update {BIAOSHOP} set shop_balance = shop_balance + {price} where shop_id ='{shopid}';");
                                retint = mainsql.SqlExcuteNoReturn(cmd);

                                //生成青贯流水号
                                qgliushuinumber = GetLdpLiushui(mainsql);

                                cmd = string.Format("INSERT INTO {0} (zf_time,zf_type,zf_status,zf_qgnumber,zf_chnumber,zf_companyaccount," +
                                "zf_companynumber,zf_companyname,zf_companyamount,zf_companyrealtimebalance,zf_default,zf_zfphone,zf_way,zf_shouzhi,zf_comshouzhi,zf_biaoid)" +
                                " VALUES ('{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','提款','2','1','{13}')",
                                BIAOQGZHIFURECORD + DateTime.Now.ToString("yyyyMM"), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                                "商家分材料款", "支付成功", qgliushuinumber,
                                "", shopid, shopid, "商家分材料款", price.ToString("0.00"),
                                price.ToString("0.00"), "商家分材料款", "", repair_id);

                                retint = mainsql.SqlExcuteNoReturn(cmd);
                                if (retint != 1)
                                {
                                    mainsql.closesql();
                                    ret.Map_Args["ErrorMsg"] = "插入记录失败";
                                    goto EXIT;
                                }


                            }
                        }
                        #endregion

                        #region 修理厂分钱

                        double dbrepair_companystar = 0;
                        double.TryParse(repair_companystar, out dbrepair_companystar);

                        sqlwhere = string.Format("WHERE user_id ='{0}' ", repair_companyid);
                        ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} {1};", BIAOUSERCOMPANY, sqlwhere));
                        if (ds.Rows.Count == 0)
                        {
                            mainsql.closesql();
                            ret.Map_Args["ErrorMsg"] = "没有相关站点";
                            goto EXIT;
                        }

                        double config_companyrepairbili = ds.Rows[0]["user_rate"].ToDouble(); ;
                        double companyprice = 0, cailiaocompanyprice = 0;
                        cailiaocompanyprice = (repair_productprice * config_companyrepairbili * dbrepair_companystar) / 5;
                        companyprice = cailiaocompanyprice + repair_serviceprice + repair_gongshiprice;
                        companyprice = Math.Round(companyprice, 2);
                        cmd = string.Format(" update {0} set repair_status2='1' where repair_id ='{1}' ;", BIAOUSERREPAIR, repair_id);
                        retint = mainsql.SqlExcuteNoReturn(cmd);
                        if (retint != 1)
                        {
                            mainsql.closesql();
                            ret.Map_Args["ErrorMsg"] = "修改订单状态失败";
                            goto EXIT;
                        }

                        cmd = string.Format(" update {0} set user_price=user_price+{1} where user_id ='{2}' ;",
                            BIAOUSERCOMPANY, companyprice, repair_companyid);
                        retint = mainsql.SqlExcuteNoReturn(cmd);
                        if (retint != 1)
                        {
                            mainsql.closesql();
                            ret.Map_Args["ErrorMsg"] = "修改修理厂零钱失败";
                            goto EXIT;
                        }


                        //生成青贯流水号

                        qgliushuinumber = GetLdpLiushui(mainsql);



                        cmd = string.Format("INSERT INTO {0} (zf_time,zf_type,zf_status,zf_qgnumber,zf_chnumber,zf_companyaccount," +
                        "zf_companynumber,zf_companyname,zf_companyamount,zf_companyrealtimebalance,zf_default,zf_zfphone,zf_way,zf_shouzhi,zf_comshouzhi,zf_biaoid)" +
                        " VALUES ('{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','提款','2','1','{13}')",
                        BIAOQGZHIFURECORD + DateTime.Now.ToString("yyyyMM"), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                        "修理厂分维修款", "支付成功", qgliushuinumber,
                        "", repair_companyid, "", repair_companyname, companyprice.ToString("0.00"),
                        companyprice.ToString("0.00"), "修理厂分维修款", "", repair_id);

                        retint = mainsql.SqlExcuteNoReturn(cmd);
                        if (retint != 1)
                        {
                            mainsql.closesql();
                            ret.Map_Args["ErrorMsg"] = "插入记录失败";
                            goto EXIT;
                        }



                        #endregion
                    }





                    #region 发微信消息
                    {


                        var user_binduserid = mainsql.SqlExecuteScalar($"select user_binduserid from {BIAOUSERCOMPANY} where user_id='{repair_companyid}'").ToString();
                        var ids = user_binduserid.Split(",".ToArray(), StringSplitOptions.RemoveEmptyEntries);
                        var user_onlyids = string.Join("','", ids);
                        var userModel = mainsql.SqlExcuteWithReturn($"select user_openid_juhesheng from {BIAOUSER} where user_phone IN ('{user_onlyids}')  ").ToModels();

                        foreach (var uitem in userModel)
                        {
                            var openid = uitem["user_openid_juhesheng"];
                            loginfo.Info("获取open:" + openid);
                            if (!string.IsNullOrWhiteSpace(openid))
                            {
                                //发送消息
                                WebServiceShopping.wechartTools.SendMsgGZH(new WebServiceShopping.wechartTools.PingJiaMsg()
                                {
                                    miniprogram = new WebServiceShopping.wechartTools.XCXPath()
                                    {
                                        pagepath = $"/pages/my/repairfactory/index/index?companyid={repair_companyid}"
                                    },
                                    touser = openid,
                                    data = new WebServiceShopping.wechartTools.PingJiaMsg.DataModel()
                                    {
                                        first = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = $"您的客户已经评价！"
                                        },
                                        keyword1 = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = $"【{repair_username}】-({repair_carplate})"
                                        },
                                        keyword2 = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = DateTime.Now.ToString("yyyy年MM月dd HH:mm")
                                        },
                                        keyword3 = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = repair_companystar + "颗星"
                                        },
                                        keyword4 = new WebServiceShopping.wechartTools.DataItem()
                                        {
                                            value = repair_companydefalut
                                        },
                                    }
                                });
                            }
                        }
                    }
                    #endregion

                    mainsql.closesql();
                    tsall.Complete();
                    ret.Byte_Flag = (sbyte)1;
                }
            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                loginfo.Info(ex);
            }

        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }


        [WebMethod(Description = "查看某一个订单评价")]
        public string All_GetRepairPingjia(string msg)
        {
            ILog loginfo = LogManager.GetLogger("LoggerJieKou");

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);
            mysqlcli mainsql = new mysqlcli();

            try
            {
                var repair_id = comrcv.Map_Args["repair_id"];


                using (TransactionScope tsall = new TransactionScope())
                {
                    mainsql.openShopServicesql();
                    string sqlwhere = string.Format("WHERE repair_repairid ='{0}' ", repair_id);

                    var ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} {1};", BIAOCOMPANYREPAIR, sqlwhere));
                    if (ds.Rows.Count == 0)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "没有相关订单";
                        goto EXIT;
                    }
                    ret.Maplist_MapArgs = new Dictionary<string, List<Dictionary<string, string>>>();
                    ret.Maplist_MapArgs.Add("datas", ds.ToModels());




                    mainsql.closesql();
                    tsall.Complete();
                    ret.Byte_Flag = (sbyte)1;
                }

            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                loginfo.Info(ex);
            }

        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }


        [WebMethod(Description = "查看某一个修理厂评价")]
        public string All_GetCompanyPingjia(string msg)
        {
            ILog loginfo = LogManager.GetLogger("LoggerJieKou");

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);
            mysqlcli mainsql = new mysqlcli();

            try
            {
                var company_id = comrcv.Map_Args["company_id"];


                using (TransactionScope tsall = new TransactionScope())
                {
                    mainsql.openShopServicesql();
                    string sqlwhere = string.Format("WHERE repair_companyid ='{0}' ", company_id);

                    var ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} {1};", BIAOCOMPANYREPAIR, sqlwhere));
                    if (ds.Rows.Count == 0)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "没有相关订单";
                        goto EXIT;
                    }
                    ret.Maplist_MapArgs = new Dictionary<string, List<Dictionary<string, string>>>();
                    ret.Maplist_MapArgs.Add("datas", ds.ToModels());

                    mainsql.closesql();
                    tsall.Complete();
                    ret.Byte_Flag = (sbyte)1;
                }

            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                loginfo.Info(ex);
            }

        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }


        #endregion

        #region 提现到虚拟账户

        [WebMethod(Description = "修理厂提现到零钱余额提醒消息")]//6-1-X
        public string Company_GetRepairPricemsg(string msg)
        {
            ILog loginfo = LogManager.GetLogger("LoggerJieKou");

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);
            mysqlcli mainsql = new mysqlcli();

            try
            {
                var repair_id = comrcv.Map_Args["repair_id"];


                loginfo.Info("修理厂提现到零钱余额提醒消息--" + repair_id);

                mainsql.openShopServicesql();
                string sqlwhere = string.Format("WHERE repair_id ='{0}' AND repair_status2='0' AND repair_status1='6' ", repair_id);

                var ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} {1};", BIAOUSERREPAIR, sqlwhere));
                if (ds.Rows.Count == 0)
                {
                    mainsql.closesql();
                    ret.Map_Args["ErrorMsg"] = "订单不能提现";
                    goto EXIT;
                }
                double repair_productprice = ds.Rows[0]["repair_productprice"].ToDouble();
                double repair_serviceprice = ds.Rows[0]["repair_serviceprice"].ToDouble();
                double repair_gongshiprice = ds.Rows[0]["repair_gongshiprice"].ToDouble();
                string repair_companyid = ds.Rows[0]["repair_companyid"].ToString();
                string repair_companyname = ds.Rows[0]["repair_companyname"].ToString();
                string repair_shopid = ds.Rows[0]["repair_shopid"].ToString();

                sqlwhere = string.Format("WHERE repair_repairid ='{0}' ", repair_id);
                ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} {1};", BIAOCOMPANYREPAIR, sqlwhere));
                if (ds.Rows.Count == 0)
                {
                    mainsql.closesql();
                    ret.Map_Args["ErrorMsg"] = "没有相关订单";
                    goto EXIT;
                }
                double repair_companystar = ds.Rows[0]["repair_companystar"].ToInt32(); ;



                sqlwhere = string.Format("WHERE user_id ='{0}' ", repair_companyid);
                ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} {1};", BIAOUSERCOMPANY, sqlwhere));
                if (ds.Rows.Count == 0)
                {
                    mainsql.closesql();
                    ret.Map_Args["ErrorMsg"] = "没有相关站点";
                    goto EXIT;
                }




                double config_companyrepairbili = ds.Rows[0]["user_rate"].ToDouble(); ;


                double companyprice = 0, cailiaocompanyprice = 0;
                cailiaocompanyprice = (repair_productprice * config_companyrepairbili * repair_companystar) / 5;

                if (repair_shopid == repair_companyid)//如果修理厂也是卖家
                {
                    double user_salerate = ds.Rows[0]["user_salerate"].ToDouble();
                    cailiaocompanyprice += repair_productprice * user_salerate;
                }

                companyprice = cailiaocompanyprice + repair_serviceprice + repair_gongshiprice;
                companyprice = Math.Round(companyprice, 2);

                string allmsg = $"请确认您的维修单服务费{repair_serviceprice}元,工时费{repair_gongshiprice}元,平台奖励{cailiaocompanyprice}元，共计{companyprice}元。";

                ret.Map_Args.Add("allmsg", allmsg);
                mainsql.closesql();

                ret.Byte_Flag = (sbyte)1;


            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                loginfo.Info(ex);
            }

        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }


        [WebMethod(Description = "修理厂提现到零钱余额")]//6-1-X
        public string Company_GetRepairPrice(string msg)
        {
            ILog loginfo = LogManager.GetLogger("LoggerJieKou");

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);
            mysqlcli mainsql = new mysqlcli();

            try
            {
                var repair_id = comrcv.Map_Args["repair_id"];


                loginfo.Info("修理厂提现到零钱余额--" + repair_id);
                using (TransactionScope tsall = new TransactionScope())
                {
                    mainsql.openShopServicesql();
                    string sqlwhere = string.Format("WHERE repair_id ='{0}' AND repair_status2='0' AND repair_status1='6' ", repair_id);

                    var ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} {1};", BIAOUSERREPAIR, sqlwhere));
                    if (ds.Rows.Count == 0)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "订单不能提现";
                        goto EXIT;
                    }
                    double repair_productprice = ds.Rows[0]["repair_productprice"].ToDouble();
                    double repair_serviceprice = ds.Rows[0]["repair_serviceprice"].ToDouble();
                    double repair_gongshiprice = ds.Rows[0]["repair_gongshiprice"].ToDouble();
                    string repair_companyid = ds.Rows[0]["repair_companyid"].ToString();
                    string repair_companyname = ds.Rows[0]["repair_companyname"].ToString();
                    string repair_shopid = ds.Rows[0]["repair_shopid"].ToString();
                    sqlwhere = string.Format("WHERE repair_repairid ='{0}' ", repair_id);
                    ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} {1};", BIAOCOMPANYREPAIR, sqlwhere));
                    if (ds.Rows.Count == 0)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "没有相关订单";
                        goto EXIT;
                    }
                    double repair_companystar = ds.Rows[0]["repair_companystar"].ToInt32(); ;



                    sqlwhere = string.Format("WHERE user_id ='{0}' ", repair_companyid);
                    ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} {1};", BIAOUSERCOMPANY, sqlwhere));
                    if (ds.Rows.Count == 0)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "没有相关站点";
                        goto EXIT;
                    }



                    double config_companyrepairbili = ds.Rows[0]["user_rate"].ToDouble(); ;


                    double companyprice = 0, cailiaocompanyprice = 0;
                    cailiaocompanyprice = (repair_productprice * config_companyrepairbili * repair_companystar) / 5;

                    if (repair_shopid == repair_companyid)//如果修理厂也是卖家
                    {
                        double user_salerate = ds.Rows[0]["user_salerate"].ToDouble();
                        cailiaocompanyprice += repair_productprice * user_salerate;
                    }

                    companyprice = cailiaocompanyprice + repair_serviceprice + repair_gongshiprice;
                    companyprice = Math.Round(companyprice, 2);

                    string cmd = string.Format(" update {0} set repair_status2='1' where repair_id ='{1}' ;", BIAOUSERREPAIR, repair_id);
                    int retint = mainsql.SqlExcuteNoReturn(cmd);
                    if (retint != 1)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "修改订单状态失败";
                        goto EXIT;
                    }

                    cmd = string.Format(" update {0} set user_price=user_price+{1} where user_id ='{2}' ;",
                        BIAOUSERCOMPANY, companyprice, repair_companyid);
                    retint = mainsql.SqlExcuteNoReturn(cmd);
                    if (retint != 1)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "修改修理厂零钱失败";
                        goto EXIT;
                    }


                    //生成青贯流水号

                    string qgliushuinumber = GetLdpLiushui(mainsql);



                    string sqlcmd = string.Format("INSERT INTO {0} (zf_time,zf_type,zf_status,zf_qgnumber,zf_chnumber,zf_companyaccount," +
                    "zf_companynumber,zf_companyname,zf_companyamount,zf_companyrealtimebalance,zf_default,zf_zfphone,zf_way,zf_shouzhi,zf_comshouzhi,zf_biaoid)" +
                    " VALUES ('{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','提款','2','1','{13}')",
                    BIAOQGZHIFURECORD + DateTime.Now.ToString("yyyyMM"), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                    "修理厂提取维修款", "支付成功", qgliushuinumber,
                    "", repair_companyid, "", repair_companyname, companyprice.ToString("0.00"),
                    companyprice.ToString("0.00"), "修理厂提取维修款", "", repair_id);

                    retint = mainsql.SqlExcuteNoReturn(sqlcmd);
                    if (retint != 1)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "插入记录失败";
                        goto EXIT;
                    }


                    mainsql.closesql();
                    tsall.Complete();
                    ret.Byte_Flag = (sbyte)1;
                }

            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                loginfo.Info(ex);
            }

        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }


        [WebMethod(Description = "商家提现到零钱余额消息提醒")]//6-X-1
        public string Shop_GetRepairPricemsg(string msg)
        {
            ILog loginfo = LogManager.GetLogger("LoggerJieKou");

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);
            mysqlcli mainsql = new mysqlcli();

            try
            {
                var repair_id = comrcv.Map_Args["repair_id"];


                loginfo.Info("商家提现到零钱余额消息提醒--" + repair_id);
                using (TransactionScope tsall = new TransactionScope())
                {
                    mainsql.openShopServicesql();
                    string sqlwhere = string.Format("WHERE repair_id ='{0}' AND repair_status3='0' AND repair_status1='6' ", repair_id);

                    var ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} {1};", BIAOUSERREPAIR, sqlwhere));
                    if (ds.Rows.Count == 0)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "订单不能提现";
                        goto EXIT;
                    }
                    double repair_productprice = ds.Rows[0]["repair_productprice"].ToDouble();

                    string repair_shopid = ds.Rows[0]["repair_shopid"].ToString();



                    ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} where  shop_id='{1}';", BIAOSHOP, repair_shopid));
                    if (ds.Rows.Count == 0)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "没有相关店铺";
                        goto EXIT;
                    }

                    double shop_addrate = ds.Rows[0]["shop_addrate"].ToDouble();

                    shop_addrate = 1 / shop_addrate;


                    double price = 0;
                    price = repair_productprice * shop_addrate;
                    price = Math.Round(price, 2);

                    string allmsg = $"请确认您的维修材料费用报价{repair_productprice},去除修理厂返点之后共计{price}元。";

                    ret.Map_Args.Add("allmsg", allmsg);

                    mainsql.closesql();
                    tsall.Complete();
                    ret.Byte_Flag = (sbyte)1;
                }

            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                loginfo.Info(ex);
            }

        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }


        [WebMethod(Description = "商家提现到零钱余额")]//6-X-1
        public string Shop_GetRepairPrice(string msg)
        {
            ILog loginfo = LogManager.GetLogger("LoggerJieKou");

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);
            mysqlcli mainsql = new mysqlcli();

            try
            {
                var repair_id = comrcv.Map_Args["repair_id"];


                loginfo.Info("商家提现到零钱余额--" + repair_id);
                using (TransactionScope tsall = new TransactionScope())
                {
                    mainsql.openShopServicesql();
                    string sqlwhere = string.Format("WHERE repair_id ='{0}' AND repair_status3='0' AND repair_status1='6' ", repair_id);

                    var ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} {1};", BIAOUSERREPAIR, sqlwhere));
                    if (ds.Rows.Count == 0)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "订单不能提现";
                        goto EXIT;
                    }
                    double repair_productprice = ds.Rows[0]["repair_productprice"].ToDouble();

                    string repair_shopid = ds.Rows[0]["repair_shopid"].ToString();



                    ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} where  shop_id='{1}';", BIAOSHOP, repair_shopid));
                    if (ds.Rows.Count == 0)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "没有相关店铺";
                        goto EXIT;
                    }

                    double shop_addrate = ds.Rows[0]["shop_addrate"].ToDouble();
                    shop_addrate = 1 / shop_addrate;
                    double price = 0;
                    price = repair_productprice * shop_addrate;
                    price = Math.Round(price, 2);

                    string cmd = string.Format(" update {0} set repair_status3='1' where repair_id ='{1}' ;", BIAOUSERREPAIR, repair_id);
                    int retint = mainsql.SqlExcuteNoReturn(cmd);
                    if (retint != 1)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "修改订单状态失败";
                        goto EXIT;
                    }

                    cmd = string.Format(" update {0} set shop_balance=shop_balance+{1} where shop_id ='{2}' ;",
                        BIAOSHOP, price, repair_shopid);
                    retint = mainsql.SqlExcuteNoReturn(cmd);
                    if (retint != 1)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "修改商家零钱失败";
                        goto EXIT;
                    }


                    //生成青贯流水号
                    string qgliushuinumber = GetLdpLiushui(mainsql);

                    string sqlcmd = string.Format("INSERT INTO {0} (zf_time,zf_type,zf_status,zf_qgnumber,zf_chnumber,zf_companyaccount," +
                    "zf_companynumber,zf_companyname,zf_companyamount,zf_companyrealtimebalance,zf_default,zf_zfphone,zf_way,zf_shouzhi,zf_comshouzhi,zf_biaoid)" +
                    " VALUES ('{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','提款','2','1','{13}')",
                    BIAOQGZHIFURECORD + DateTime.Now.ToString("yyyyMM"), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                    "商家提取材料款", "支付成功", qgliushuinumber,
                    "", repair_shopid, "", "", price.ToString("0.00"),
                    price.ToString("0.00"), "商家提取材料款", "", repair_id);

                    retint = mainsql.SqlExcuteNoReturn(sqlcmd);
                    if (retint != 1)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "插入记录失败";
                        goto EXIT;
                    }


                    mainsql.closesql();
                    tsall.Complete();
                    ret.Byte_Flag = (sbyte)1;
                }

            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                loginfo.Info(ex);
            }

        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }

        #endregion

        #region 修理厂代码

        [WebMethod(Description = "查询单位列表")]
        public string Shop_FindCompany(string msg)
        {
            ILog loginfo = LogManager.GetLogger("LoggerJieKou");

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);

            mysqlcli mainsql = new mysqlcli();

#if DEBUG
            mainsql.opensql(new SqlInfo()
            {
                String_sqlip = "127.0.0.1",
                String_sqlname = "shopping",
                String_sqlport = "3306",
                String_sqlpwd = "123456",
                String_sqluser = "root"
            });
#else
            mainsql.openShopServicesql();
#endif

            try
            {
                using (TransactionScope tsall = new TransactionScope())
                {
                    StringBuilder sqlwhere = new StringBuilder(" where 1=1");
                    if (comrcv.Map_Args.ContainsKey("name"))
                    {
                        sqlwhere.AppendFormat(" and user_companyname like '%{0}%'", comrcv.Map_Args["name"]);
                    }

                    var ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} {1}", BIAOUSERCOMPANY, sqlwhere.ToString()));

                    ret.Maplist_MapArgs = new Dictionary<string, List<Dictionary<string, string>>>();
                    var lis = ds.ToModels();

                    ret.Maplist_MapArgs.Add("Datas", lis);


                    mainsql.closesql();
                    tsall.Complete();
                    ret.Byte_Flag = (sbyte)1;
                }
            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                loginfo.Info(ex);
            }

        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }

        [WebMethod(Description = "查询是否绑定修理厂")]
        public string Shop_CheckCompany(string msg)
        {
            ILog loginfo = LogManager.GetLogger("LoggerJieKou");

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);
            mysqlcli mainsql = new mysqlcli();
            mainsql.openShopServicesql();
            string name = comrcv.Map_Args["name"];
            string phone = comrcv.Map_Args["phone"];
            string userid = comrcv.Map_Args["userid"];

            loginfo.Info("查询是否绑定修理厂--" + name);
            try
            {
                string cmd = string.Format("select * from {0} where user_binduserid like '%{1}%'", BIAOUSERCOMPANY, phone);

                DataTable ds = mainsql.SqlExcuteWithReturn(cmd);

                if (ds.Rows.Count == 0)
                {
                    ds.Dispose();
                    mainsql.closesql();
                    goto EXIT;
                }
                ret.Maplist_MapArgs = new Dictionary<string, List<Dictionary<string, string>>>();
                ret.Maplist_MapArgs.Add("Datas", ds.ToModels());

                var ids = new List<string>();
                DataRow item = ds.Rows[0] as DataRow;
                var img = item["user_mentou"]?.ToString();
                if (!string.IsNullOrWhiteSpace(img))
                {
                    ids.Add(img);
                }
                img = item["user_scene"]?.ToString();
                if (!string.IsNullOrWhiteSpace(img))
                {

                    ids.AddRange(img.Split(",".ToArray(), StringSplitOptions.RemoveEmptyEntries));
                }
                img = item["user_business"]?.ToString();
                if (!string.IsNullOrWhiteSpace(img))
                {
                    ids.Add(img);
                }
                if (ids.Count > 0)
                {
                    var files = mainsql.SqlExcuteWithReturn($"select * from {BIAOSHOPFILE} where file_id in ('{string.Join("','", ids)}')").ToModels();
                    ret.Maplist_MapArgs.Add("Files", files);
                }
                string companyid = item["user_id"]?.ToString();
                string user_createtime = DateTime.Now.ToString("yyyy-MM");
                cmd = string.Format("select count(*) from {0} where repair_companyid = '{1}' and repair_createtime > '{2}' ",
                BIAOUSERREPAIR, companyid, user_createtime);
                ret.Map_Args.Add("newdan", mainsql.SqlExcuteCountReturn(cmd));
                cmd = string.Format("select count(*) from {0} where repair_companyid = '{1}' and repair_createtime > '{2}' AND repair_status1='6' ",
                         BIAOUSERREPAIR, companyid, user_createtime);
                ret.Map_Args.Add("wandan", mainsql.SqlExcuteCountReturn(cmd));

                ret.Map_Args.Add("buyorderCount", mainsql.SqlExcuteCountReturn($"select count(1) from s_commoditybuyorder where (buy_order_pay_status = 1 || buy_order_pay_status = 6) && buy_order_status = 0  and company_id='{item["user_id"]}'"));

                mainsql.closesql();
                ret.Byte_Flag = (sbyte)1;

            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                loginfo.Info(ex);
            }

        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }

        [WebMethod(Description = "新建修理厂")]
        public string Shop_NewCompany(string msg)
        {
            ILog loginfo = LogManager.GetLogger("LoggerJieKou");

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);
            mysqlcli mainsql = new mysqlcli();
            mainsql.openShopServicesql();
            try
            {
                string name = comrcv.Map_Args["name"];
                string phone = comrcv.Map_Args["phone"];
                string userid = comrcv.Map_Args["userid"];

                var cname = comrcv.Map_Args["user_companyname"];
                var ctel = comrcv.Map_Args["user_companytel"];
                var fuzeren = comrcv.Map_Args["user_person"];
                var fuzerentel = comrcv.Map_Args["user_persontel"];
                var cpath = comrcv.Map_Args["user_companypath"];


                var changjing = comrcv.Map_Args["user_scene"];
                var yingyezhizhao = comrcv.Map_Args["user_business"];

                var mentou = comrcv.Map_Args["user_mentou"];

                var user_longitude = comrcv.Map_Args["user_longitude"];
                var user_latitude = comrcv.Map_Args["user_latitude"];
                var user_service = comrcv.Map_Args["user_service"];
                var user_cartype_ids = comrcv.Map_Args["carTypeIds"];
                var user_skill_label = comrcv.Map_Args["skillLable"];

                var tuiguangma = comrcv.Map_Args.ContainsKey("user_tuiguangma") ? comrcv.Map_Args["user_tuiguangma"] : string.Empty;

                var user_businesshours = comrcv.Map_Args.ContainsKey("user_businesshours") ? comrcv.Map_Args["user_businesshours"] : string.Empty;
                var user_starwork = comrcv.Map_Args.ContainsKey("user_starwork") ? comrcv.Map_Args["user_starwork"] : string.Empty;

                string user_binduserid = phone;
                string user_createtime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                string companyid = Guid.NewGuid().ToString();
                loginfo.Info("查询是否绑定修理厂--" + name);


                var fileIds = new List<string>();
                if (!string.IsNullOrWhiteSpace(mentou))
                    fileIds.Add(mentou);

                if (!string.IsNullOrWhiteSpace(changjing))
                {
                    fileIds.AddRange(changjing.Split(",".ToArray(), StringSplitOptions.RemoveEmptyEntries));
                }
                if (!string.IsNullOrWhiteSpace(yingyezhizhao))
                    fileIds.Add(yingyezhizhao);

                ConvertTemporary(mainsql, string.Join(",", fileIds));

                using (TransactionScope tsall = new TransactionScope())
                {
                    int sqlret = mainsql.SqlExcuteNoReturn($"insert into {BIAOUSERCOMPANY}(user_id,user_tuiguangma," +
                    "user_companyname,user_companytel,user_person,user_persontel,user_companypath,user_mentou," +
                    "user_scene,user_business,user_longitude,user_latitude,user_binduserid,user_service,user_createtime,user_businesshours,user_starwork,user_cartype_ids,user_skill_label)"
                   + $" values('{companyid}','{tuiguangma}','{cname}','{ctel}','{fuzeren}','{fuzerentel}','{cpath}','{mentou}','{changjing}','{yingyezhizhao}','{user_longitude}','{user_latitude}','{user_binduserid}','{user_service}','{user_createtime}','{user_businesshours}','{user_starwork}','{user_cartype_ids}','{user_skill_label}')");
                    if (sqlret != 1)
                    {
                        ret.Map_Args["ErrorMsg"] = "新建失败";  //参数错误
                        goto EXIT;
                    }

                    mainsql.closesql();
                    tsall.Complete();
                    ret.Byte_Flag = (sbyte)1;
                }

            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                loginfo.Info(ex);
            }

        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }

        [WebMethod(Description = "修改修理厂")]
        public string Shop_ChangeCompany(string msg)
        {
            ILog loginfo = LogManager.GetLogger("LoggerJieKou");

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);
            mysqlcli mainsql = new mysqlcli();
            mainsql.openShopServicesql();
            try
            {

                var user_companyid = comrcv.Map_Args["user_companyid"];
                var cname = comrcv.Map_Args["user_companyname"];
                var ctel = comrcv.Map_Args["user_companytel"];
                var cpath = comrcv.Map_Args["user_companypath"];
                var changjing = comrcv.Map_Args["user_scene"];
                var yingyezhizhao = comrcv.Map_Args["user_business"];
                var mentou = comrcv.Map_Args["user_mentou"];
                var user_longitude = comrcv.Map_Args["user_longitude"];
                var user_latitude = comrcv.Map_Args["user_latitude"];
                var user_service = comrcv.Map_Args["user_service"];
                var user_cartype_ids = comrcv.Map_Args["carTypeIds"];
                var user_skill_label = comrcv.Map_Args["skillLable"];
                var tuiguangma = comrcv.Map_Args.ContainsKey("user_tuiguangma") ? comrcv.Map_Args["user_tuiguangma"] : string.Empty;
                var user_businesshours = comrcv.Map_Args.ContainsKey("user_businesshours") ? comrcv.Map_Args["user_businesshours"] : string.Empty;
                var user_starwork = comrcv.Map_Args.ContainsKey("user_starwork") ? comrcv.Map_Args["user_starwork"] : string.Empty;

                loginfo.Info("修改修理厂--" + cname);


                var fileIds = new List<string>();
                if (!string.IsNullOrWhiteSpace(mentou))
                    fileIds.Add(mentou);
                if (!string.IsNullOrWhiteSpace(changjing))
                {
                    fileIds.AddRange(changjing.Split(",".ToArray(), StringSplitOptions.RemoveEmptyEntries));
                }
                if (!string.IsNullOrWhiteSpace(yingyezhizhao))
                    fileIds.Add(yingyezhizhao);
                ConvertTemporary(mainsql, string.Join(",", fileIds));

                using (TransactionScope tsall = new TransactionScope())
                {

                    string updatestr = string.Format(" user_companyname='{0}' , ", comrcv.Map_Args["user_companyname"]);
                    updatestr += string.Format(" user_companytel='{0}' , ", comrcv.Map_Args["user_companytel"]);
                    updatestr += string.Format(" user_scene='{0}' , ", comrcv.Map_Args["user_scene"]);
                    updatestr += string.Format(" user_business='{0}' , ", comrcv.Map_Args["user_business"]);
                    updatestr += string.Format(" user_mentou='{0}' , ", comrcv.Map_Args["user_mentou"]);
                    updatestr += string.Format(" user_companypath='{0}' , ", comrcv.Map_Args["user_companypath"]);

                    updatestr += string.Format(" user_longitude='{0}' , ", comrcv.Map_Args["user_longitude"]);
                    updatestr += string.Format(" user_latitude='{0}' , ", comrcv.Map_Args["user_latitude"]);

                    updatestr += string.Format(" user_tuiguangma='{0}', ", tuiguangma);

                    updatestr += string.Format(" user_businesshours='{0}', ", user_businesshours);
                    updatestr += string.Format(" user_starwork='{0}', ", user_starwork);

                    updatestr += string.Format(" user_service='{0}', ", user_service);
                    updatestr += string.Format(" user_cartype_ids='{0}', ", user_cartype_ids);
                    updatestr += string.Format(" user_skill_label='{0}' ", user_skill_label);




                    string cmd = string.Format(" update {0} set {1} where user_id ='{2}' ;", BIAOUSERCOMPANY, updatestr, user_companyid);
                    loginfo.Info(cmd);
                    int retint = mainsql.SqlExcuteNoReturn(cmd);
                    if (retint != 1)
                    {
                        ret.Map_Args["ErrorMsg"] = "修改失败";
                        goto EXIT;
                    }



                    mainsql.closesql();
                    tsall.Complete();
                    ret.Byte_Flag = (sbyte)1;
                }

            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                loginfo.Info(ex);
            }

        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }

        [WebMethod(Description = "新增绑定手机")]
        public string Shop_Adduserid(string msg)
        {
            ILog loginfo = LogManager.GetLogger("LoggerJieKou");

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);
            mysqlcli mainsql = new mysqlcli();
            mainsql.openShopServicesql();
            try
            {
                string companyid = comrcv.Map_Args["companyid"];//修理厂的id
                string phone = comrcv.Map_Args["phone"];//新绑定的id

                string cmd = string.Format("select * from {0} where user_id='{1}'; ", BIAOUSERCOMPANY, companyid);

                DataTable ds = mainsql.SqlExcuteWithReturn(cmd);
                if (ds.Rows.Count == 0)
                {
                    mainsql.closesql();
                    ret.Map_Args["ErrorMsg"] = "没有查询到相关修理厂";  //参数错误
                    goto EXIT;
                }
                string oldstr = ds.Rows[0]["user_binduserid"].ToString();
                if (oldstr.IndexOf(phone) == -1)
                {
                    oldstr = oldstr + "," + phone;
                }
                cmd = string.Format(" UPDATE  {0} Set user_binduserid='{1}'  where user_id = '{2}' ",
                BIAOUSERCOMPANY, oldstr, companyid);
                int sqlret = mainsql.SqlExcuteNoReturn(cmd);
                mainsql.closesql();
                if (sqlret < 1)
                {
                    ret.Map_Args["ErrorMsg"] = "修改数据失败";  //参数错误
                    goto EXIT;
                }

                mainsql.closesql();
                ret.Byte_Flag = (sbyte)1;

            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                loginfo.Info(ex);
            }

        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }

        [WebMethod(Description = "解除绑定手机")]
        public string Shop_Deluserid(string msg)
        {
            ILog loginfo = LogManager.GetLogger("LoggerJieKou");

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);
            mysqlcli mainsql = new mysqlcli();
            mainsql.openShopServicesql();
            try
            {
                string companyid = comrcv.Map_Args["companyid"];//修理厂的id
                string phone = comrcv.Map_Args["phone"];//要删除的手机号码

                string cmd = string.Format("select * from {0} where user_id='{1}'; ", BIAOUSERCOMPANY, companyid);

                DataTable ds = mainsql.SqlExcuteWithReturn(cmd);
                if (ds.Rows.Count == 0)
                {
                    mainsql.closesql();
                    ret.Map_Args["ErrorMsg"] = "没有查询到相关修理厂";  //参数错误
                    goto EXIT;
                }
                string oldstr = ds.Rows[0]["user_binduserid"].ToString();
                oldstr = oldstr.Replace(phone, "");
                cmd = string.Format(" UPDATE  {0} Set user_binduserid='{1}'  where user_id = '{2}' ",
            BIAOUSERCOMPANY, oldstr, companyid);
                int sqlret = mainsql.SqlExcuteNoReturn(cmd);
                mainsql.closesql();
                if (sqlret < 1)
                {
                    ret.Map_Args["ErrorMsg"] = "修改数据失败";  //参数错误
                    goto EXIT;
                }

                mainsql.closesql();
                ret.Byte_Flag = (sbyte)1;

            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                loginfo.Info(ex);
            }

        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }

        [WebMethod(Description = "获取修理厂绑定手机的用户信息")]
        public string Shop_getallbinduser(string msg)
        {
            ILog loginfo = LogManager.GetLogger("LoggerJieKou");

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);
            mysqlcli mainsql = new mysqlcli();
            mainsql.openShopServicesql();
            try
            {
                string companyid = comrcv.Map_Args["companyid"];//修理厂的id


                string cmd = string.Format("select * from {0} where user_id='{1}'; ", BIAOUSERCOMPANY, companyid);

                DataTable ds = mainsql.SqlExcuteWithReturn(cmd);
                if (ds.Rows.Count == 0)
                {
                    mainsql.closesql();
                    ret.Map_Args["ErrorMsg"] = "没有查询到相关修理厂";  //参数错误
                    goto EXIT;
                }
                string phonestr = ds.Rows[0]["user_binduserid"].ToString();
                string[] biaoidarr = phonestr.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                string inbiaoidsstr = "'" + string.Join("','", biaoidarr) + "'";

                cmd = string.Format("select * from {0} where user_phone in ({1}); ", BIAOUSER, inbiaoidsstr);

                ds = mainsql.SqlExcuteWithReturn(cmd);

                ret.Maplist_MapArgs = new Dictionary<string, List<Dictionary<string, string>>>();

                ret.Maplist_MapArgs.Add("Datas", ds.ToModels());

                mainsql.closesql();
                ret.Byte_Flag = (sbyte)1;
            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                loginfo.Info(ex);
            }

        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }

        [WebMethod(Description = "查询维修记录")]
        public string Shop_GetCompanyRepairlist(string msg)
        {
            ILog loginfo = LogManager.GetLogger("LoggerJieKou");

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);
            mysqlcli mainsql = new mysqlcli();
            mainsql.openShopServicesql();
            try
            {
                var user_companyid = comrcv.Map_Args["companyid"];

                using (TransactionScope tsall = new TransactionScope())
                {

                    DataTable ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} WHERE repair_companyid ='{1}'", BIAOCOMPANYREPAIR, user_companyid));

                    ret.Maplist_MapArgs = new Dictionary<string, List<Dictionary<string, string>>>();


                    ret.Maplist_MapArgs.Add("Datas", ds.ToModels());


                    mainsql.closesql();
                    tsall.Complete();
                    ret.Byte_Flag = (sbyte)1;
                }
            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                loginfo.Info(ex);
            }

        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }

        [WebMethod(Description = "设置修理厂维修")]
        public string Shop_SetCompanyRepair(string msg)
        {
            ILog loginfo = LogManager.GetLogger("LoggerJieKou");

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);
            mysqlcli mainsql = new mysqlcli();

            try
            {
                string repair_companyid = comrcv.Map_Args["repair_companyid"];//修理厂的id
                string repair_companyname = comrcv.Map_Args["repair_companyname"];//修理厂的名称
                string repair_orderid = comrcv.Map_Args["repair_orderid"];//原订单的id
                string repair_orderprice = comrcv.Map_Args["repair_orderprice"];//原订单的金额
                string repair_username = comrcv.Map_Args["repair_username"];//用户名
                string repair_userphone = comrcv.Map_Args["repair_userphone"];//用户手机
                string repair_star = comrcv.Map_Args["repair_star"];//评价星级，1-5。1最低，5最高
                string repair_defalut = comrcv.Map_Args["repair_defalut"];//评价备注
                double bili = 0.2;
                double price = 0;
                price = Convert.ToDouble(repair_orderprice) * (Convert.ToDouble(repair_star) / 5) * bili;

                price = Math.Round(price, 2);

                using (TransactionScope tsall = new TransactionScope())
                {
                    mainsql.openShopServicesql();

                    //插入维修记录
                    string intsertkeystr = SQLCOMPANYREPAIR;
                    string intsertvaluestr = SQLCOMPANYREPAIR;
                    intsertvaluestr = intsertvaluestr.Replace("repair_createtime", "'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'");//
                    intsertvaluestr = intsertvaluestr.Replace("repair_orderid", "'" + repair_orderid + "'");//
                    intsertvaluestr = intsertvaluestr.Replace("repair_orderprice", "'" + repair_orderprice + "'");//
                    intsertvaluestr = intsertvaluestr.Replace("repair_username", "'" + repair_username + "'");//
                    intsertvaluestr = intsertvaluestr.Replace("repair_userphone", "'" + repair_userphone + "'");//
                    intsertvaluestr = intsertvaluestr.Replace("repair_companyid", "'" + repair_companyid + "'");//
                    intsertvaluestr = intsertvaluestr.Replace("repair_companyname", "'" + repair_companyname + "'");//
                    intsertvaluestr = intsertvaluestr.Replace("repair_star", "'" + repair_star + "'");//
                    intsertvaluestr = intsertvaluestr.Replace("repair_bili", "'" + bili.ToString() + "'");//
                    intsertvaluestr = intsertvaluestr.Replace("repair_price", "'" + price.ToString() + "'");//
                    intsertvaluestr = intsertvaluestr.Replace("repair_defalut", "'" + repair_defalut + "'");//

                    string cmd = string.Format("insert into {0} ({1}) values ({2}) ", BIAOCOMPANYREPAIR, intsertkeystr, intsertvaluestr);
                    int sqlret = mainsql.SqlExcuteNoReturn(cmd);
                    if (sqlret != 1)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "新增维修记录失败";
                        goto EXIT;
                    }

                    //修改修理厂金额


                    cmd = string.Format("SELECT * from {0} where user_id='{1}';", BIAOUSERCOMPANY, repair_companyid);

                    DataTable ds = mainsql.SqlExcuteWithReturn(cmd);
                    if (ds.Rows.Count == 0)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "没有这个修理厂";
                        goto EXIT;
                    }
                    double oldprice = Convert.ToDouble(ds.Rows[0]["user_price"]);
                    oldprice = oldprice + price;

                    cmd = string.Format("update {0} set user_price='{1}' where user_id='{2}' ",
                        BIAOUSERCOMPANY, oldprice, repair_companyid);
                    sqlret = mainsql.SqlExcuteNoReturn(cmd);
                    if (sqlret != 1)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "修改记录失败";
                        goto EXIT;
                    }


                    //插入流水信息

                    cmd = string.Format("SELECT * from {0} where com_account='qingguan' AND com_number='00000' ;", BIAOQGZHIFUCOMPANY);
                    ds = mainsql.SqlExcuteWithReturn(cmd);
                    string qgnumber = ds.Rows[0]["com_number"].ToString();
                    string qgnumberdate = ds.Rows[0]["com_numberdate"].ToString();



                    string qgliushuinumber = GetCompanyDDNumber(mainsql, qgnumberdate, "qingguan");
                    //生成青贯流水号
                    qgliushuinumber = qgnumber + DateTime.Now.ToString("yyyyMMddHHmmss") + qgliushuinumber;

                    string sqlcmd = string.Format("INSERT INTO {0} (zf_time,zf_type,zf_status,zf_qgnumber,zf_chnumber,zf_companyaccount," +
                    "zf_companynumber,zf_companyname,zf_companyamount,zf_companyrealtimebalance,zf_default,zf_zfphone,zf_way,zf_shouzhi,zf_comshouzhi,zf_biaoid)" +
                    " VALUES ('{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','奖励','2','1','{13}')",
                    BIAOQGZHIFURECORD + DateTime.Now.ToString("yyyyMM"), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                    "修理厂奖励", "支付成功", qgliushuinumber,
                    "", repair_companyid, "", repair_companyname, price.ToString("0.00"),
                    oldprice.ToString("0.00"), repair_defalut, repair_userphone, repair_orderid);

                    sqlret = mainsql.SqlExcuteNoReturn(sqlcmd);
                    if (sqlret != 1)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "插入记录失败";
                        goto EXIT;
                    }




                    mainsql.closesql();
                    tsall.Complete();
                    ret.Byte_Flag = (sbyte)1;
                }

            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                loginfo.Info(ex);
            }

        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }

        [WebMethod(Description = "获取修理厂账单")]
        public string Shop_GetCompanyzd(string msg)
        {
            ILog logJieKou = LogManager.GetLogger("LoggerJieKou");
            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv);
            mysqlcli mainsql = new mysqlcli();

            try
            {
                string companyid = comrcv.Map_Args["companyid"];//修理厂id
                string biaodate = comrcv.Map_Args["biaodate"];//月份
                string pageindex = comrcv.Map_Args["pageindex"];//页数

                mainsql.openYongHuServicesql();


                logJieKou.Info("获取修理厂账单-" + companyid);
                int pagecount = 100;
                int intpageindex = 0;
                int.TryParse(pageindex, out intpageindex);
                intpageindex = intpageindex * pagecount;
                string limitstring = string.Format("limit {0},{1} ", intpageindex, pagecount);


                string sqlcmd = string.Format("SELECT * FROM {0}" +
                    " where ((zf_status ='支付成功' and zf_type<>'团购支付') || zf_status='核销成功') AND zf_companyaccount='{1}' AND zf_comshouzhi <> '0' ORDER BY zf_time DESC {2} ;",
                    BIAOQGZHIFURECORD + biaodate, companyid, limitstring);
                DataTable ds = mainsql.SqlExcuteWithReturn(sqlcmd);
                mainsql.closesql();
                ret.Map_Args.Add("AllCount", ds.Rows.Count.ToString());
                ret.List_MapArgs = new List<Dictionary<string, string>>();
                if (ds.Rows.Count != 0)
                {
                    foreach (DataRow row in ds.Rows)
                    {
                        Dictionary<string, string> newNetImple = new Dictionary<string, string>();
                        foreach (DataColumn dl in ds.Columns)
                        {
                            newNetImple.Add(dl.ColumnName, row[dl.ColumnName].ToString());
                        }
                        ret.List_MapArgs.Add(newNetImple);
                    }
                }
                ds.Dispose();
            }
            catch (Exception ex)
            {
                logJieKou.Info("获取修理厂账单-" + ex.Message);
                mainsql.closesql();

                goto EXIT;
            }
            ret.Byte_Flag = (sbyte)1;
        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret);
            string retstr = Convert.ToBase64String(retb);
            return retstr;

        }




        #endregion

        #region 修理厂银行卡管理


        #region 列表查询

        [WebMethod(Description = "列表查询")]
        public string Company_CardList(string msg)
        {
            ILog loginfo = LogManager.GetLogger("LoggerJieKou");
            loginfo.Info(nameof(Shop_CardList) + ":" + msg);
            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Maplist_MapArgs = new Dictionary<string, List<Dictionary<string, string>>>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);
            mysqlcli mainsql = new mysqlcli();
            mainsql.openShopServicesql();
            try
            {
                var company_id = comrcv.Map_Args["company_id"];
                ret.Maplist_MapArgs.Add("Datas", mainsql.SqlExcuteWithReturn($"select * from {COMPANYBANKCARD} where company_id='{company_id}' and bank_deleteflag=0").ToModels());
                ret.Map_Args["ErrorMsg"] = "操作成功";
                mainsql.closesql();
                ret.Byte_Flag = (sbyte)1;
            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                loginfo.Info(ex);
            }
        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }
        #endregion

        #region 添加/编辑

        [WebMethod(Description = "添加/编辑")]
        public string Company_ModifyCard(string msg)
        {
            ILog loginfo = LogManager.GetLogger("LoggerJieKou");
            loginfo.Info(nameof(Shop_ModifyCard) + ":" + msg);
            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Maplist_MapArgs = new Dictionary<string, List<Dictionary<string, string>>>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);

            mysqlcli mainsql = new mysqlcli();
            mainsql.openShopServicesql();


            try
            {
                using (TransactionScope tsall = new TransactionScope())
                {
                    var company_id = comrcv.Map_Args["company_id"]; //店铺ID
                    var id = comrcv.Map_Args["bank_id"].ToInt32(); //原ID，如果有就是编辑
                    var name = comrcv.Map_Args["bank_name"];  //银行名
                    var number = comrcv.Map_Args["bank_cardnumber"]; //卡号
                    var username = comrcv.Map_Args["bank_username"]; //开户名
                    var isdefault = comrcv.Map_Args["bank_isdefault"].ToInt32(); //0不默认，1默认

                    var paras = new List<MySqlParameter>();
                    paras.Add(new MySqlParameter("@company_id", company_id));
                    paras.Add(new MySqlParameter("@bank_name", name));
                    paras.Add(new MySqlParameter("@bank_cardnumber", number));
                    paras.Add(new MySqlParameter("@bank_username", username));
                    paras.Add(new MySqlParameter("@bank_isdefault", isdefault));
                    paras.Add(new MySqlParameter("@id", id));
                    if (isdefault == 1)
                    {
                        mainsql.SqlExcuteNoReturn($"update {COMPANYBANKCARD} set bank_isdefault=0 where company_id=@company_id", paras.ToArray());
                    }
                    if (id > 0)
                    {
                        mainsql.SqlExcuteNoReturn($"update {COMPANYBANKCARD} set bank_name=@bank_name,bank_cardnumber=@bank_cardnumber,bank_username=@bank_username,bank_isdefault=@bank_isdefault where bank_id=@id and company_id=@company_id"
                            , paras.ToArray());
                    }
                    else
                    {
                        mainsql.SqlExcuteNoReturn($"insert into {COMPANYBANKCARD} (company_id,bank_name,bank_cardnumber,bank_username,bank_isdefault,bank_deleteflag,bank_createtime)"
                            + "values(@company_id,@bank_name,@bank_cardnumber,@bank_username,@bank_isdefault,0,NOW())"
                            , paras.ToArray());
                    }
                    ret.Maplist_MapArgs.Add("Datas", mainsql.SqlExcuteWithReturn($"select * from {COMPANYBANKCARD} where company_id='{company_id}' and bank_deleteflag=0").ToModels());

                    ret.Map_Args["ErrorMsg"] = "操作成功";
                    mainsql.closesql();
                    tsall.Complete();
                    ret.Byte_Flag = (sbyte)1;
                }
            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                loginfo.Info(ex);
            }

        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }
        #endregion

        #region 删除

        [WebMethod(Description = "删除")]
        public string Company_DelCard(string msg)
        {
            ILog loginfo = LogManager.GetLogger("LoggerJieKou");
            loginfo.Info(nameof(Shop_DelCard) + ":" + msg);
            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Maplist_MapArgs = new Dictionary<string, List<Dictionary<string, string>>>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);

            mysqlcli mainsql = new mysqlcli();

            mainsql.openShopServicesql();

            try
            {
                using (TransactionScope tsall = new TransactionScope())
                {
                    var company_id = comrcv.Map_Args["company_id"]; //店铺ID
                    var id = comrcv.Map_Args["bank_id"].ToInt32(); //id

                    var paras = new List<MySqlParameter>();
                    paras.Add(new MySqlParameter("@company_id", company_id));
                    paras.Add(new MySqlParameter("@id", id));
                    mainsql.SqlExcuteNoReturn($"update {COMPANYBANKCARD} set bank_deleteflag=1 where bank_id=@id and company_id=@company_id", paras.ToArray());

                    ret.Maplist_MapArgs.Add("Datas", mainsql.SqlExcuteWithReturn($"select * from {COMPANYBANKCARD} where company_id='{company_id}' and bank_deleteflag=0").ToModels());

                    ret.Map_Args["ErrorMsg"] = "操作成功";
                    mainsql.closesql();
                    tsall.Complete();
                    ret.Byte_Flag = (sbyte)1;
                }
            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                loginfo.Info(ex);
            }

        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }
        #endregion

        #region 设为默认

        [WebMethod(Description = "设为默认")]
        public string Company_SetDefaultCard(string msg)
        {
            ILog loginfo = LogManager.GetLogger("LoggerJieKou");
            loginfo.Info(nameof(Shop_SetDefaultCard) + ":" + msg);
            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Maplist_MapArgs = new Dictionary<string, List<Dictionary<string, string>>>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);

            mysqlcli mainsql = new mysqlcli();

#if DEBUG
            mainsql.opensql(new SqlInfo()
            {
                String_sqlip = "127.0.0.1",
                String_sqlname = "shopping",
                String_sqlport = "3306",
                String_sqlpwd = "123456",
                String_sqluser = "root"
            });
#else
            mainsql.openShopServicesql();
#endif

            try
            {
                using (TransactionScope tsall = new TransactionScope())
                {
                    var company_id = comrcv.Map_Args["company_id"]; //店铺ID
                    var id = comrcv.Map_Args["bank_id"].ToInt32(); //id

                    var paras = new List<MySqlParameter>();
                    paras.Add(new MySqlParameter("@company_id", company_id));
                    paras.Add(new MySqlParameter("@id", id));

                    mainsql.SqlExcuteNoReturn($"update {COMPANYBANKCARD} set bank_isdefault=0 where company_id=@company_id", paras.ToArray());

                    mainsql.SqlExcuteNoReturn($"update {COMPANYBANKCARD} set bank_isdefault=1 where bank_id=@id and company_id=@company_id", paras.ToArray());

                    ret.Maplist_MapArgs.Add("Datas", mainsql.SqlExcuteWithReturn($"select * from {COMPANYBANKCARD} where shop_id='{company_id}' and bank_deleteflag=0").ToModels());

                    ret.Map_Args["ErrorMsg"] = "操作成功";
                    mainsql.closesql();
                    tsall.Complete();
                    ret.Byte_Flag = (sbyte)1;
                }
            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                loginfo.Info(ex);
            }

        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }
        #endregion

        #endregion

        #region 我的爱车

        private const string USERCAR = "yonghuallusercar";
        private const string SQLUSERCAR = "car_userid,car_userphone,car_username,car_carplate,"
            + "car_carvin,car_carinfo,car_default";

        #region 列表查询

        [WebMethod(Description = "列表查询")]
        public string Yonghu_CarList(string msg)
        {

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Maplist_MapArgs = new Dictionary<string, List<Dictionary<string, string>>>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);

            mysqlcli mainsql = new mysqlcli();


            try
            {
                using (TransactionScope tsall = new TransactionScope())
                {
                    mainsql.openShopServicesql();
                    var user_id = comrcv.Map_Args["user_id"];
                    ret.Maplist_MapArgs.Add("Datas", mainsql.SqlExcuteWithReturn($"select * from {USERCAR} where car_userid='{user_id}'; ").ToModels());

                    ret.Map_Args["ErrorMsg"] = "操作成功";
                    mainsql.closesql();
                    tsall.Complete();
                    ret.Byte_Flag = (sbyte)1;
                }
            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误

            }

        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }
        #endregion

        #region 添加/编辑

        [WebMethod(Description = "添加/编辑")]
        public string Yonghu_ModifyCar(string msg)
        {

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Maplist_MapArgs = new Dictionary<string, List<Dictionary<string, string>>>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);

            mysqlcli mainsql = new mysqlcli();

            try
            {
                using (TransactionScope tsall = new TransactionScope())
                {
                    mainsql.openShopServicesql();

                    var updateflag = comrcv.Map_Args["updateflag"]; //更新标志，1就是修改，0就是新增


                    var user_id = comrcv.Map_Args["user_id"];

                    var car_userphone = comrcv.Map_Args["car_userphone"];
                    var car_username = comrcv.Map_Args["car_username"];
                    var car_carplate = comrcv.Map_Args["car_carplate"];
                    var car_carvin = comrcv.Map_Args["car_carvin"];
                    var car_carinfo = comrcv.Map_Args["car_carinfo"];
                    car_carinfo = car_carinfo.Replace("'", String.Empty);
                    var car_default = comrcv.Map_Args["car_default"];

                    if (updateflag == "1")
                    {
                        var Sid = comrcv.Map_Args["Sid"];

                        string updatestr = string.Format(" car_carplate='{0}' ", car_carplate);
                        updatestr += string.Format(" ,car_carvin='{0}' ", car_carvin);
                        updatestr += string.Format(" ,car_carinfo='{0}' ", car_carinfo);
                        updatestr += string.Format(" ,car_default='{0}' ", car_default);
                        updatestr += string.Format(" ,car_userphone='{0}' ", car_userphone);
                        updatestr += string.Format(" ,car_username='{0}' ", car_username);

                        string cmd = string.Format(" update {0} set {1} where Sid='{2}' ;", USERCAR, updatestr, Sid);
                        int retint = mainsql.SqlExcuteNoReturn(cmd);
                        if (retint != 1)
                        {
                            mainsql.closesql();
                            ret.Map_Args["ErrorMsg"] = "修改订单失败";
                            goto EXIT;
                        }
                    }
                    else
                    {
                        string intsertkeystr = SQLUSERCAR;
                        string intsertvaluestr = SQLUSERCAR;
                        intsertvaluestr = intsertvaluestr.Replace("car_userid", "'" + user_id + "'");
                        intsertvaluestr = intsertvaluestr.Replace("car_userphone", "'" + car_userphone + "'");
                        intsertvaluestr = intsertvaluestr.Replace("car_username", "'" + car_username + "'");
                        intsertvaluestr = intsertvaluestr.Replace("car_carplate", "'" + car_carplate + "'");
                        intsertvaluestr = intsertvaluestr.Replace("car_carvin", "'" + car_carvin + "'");
                        intsertvaluestr = intsertvaluestr.Replace("car_carinfo", "'" + car_carinfo + "'");
                        intsertvaluestr = intsertvaluestr.Replace("car_default", "'" + car_default + "'");

                        string cmd = string.Format("insert into {0} ({1}) values ({2}) ", USERCAR, intsertkeystr, intsertvaluestr);
                        int sqlret = mainsql.SqlExcuteNoReturn(cmd);
                        if (sqlret != 1)
                        {
                            mainsql.closesql();
                            ret.Map_Args["ErrorMsg"] = "下单失败";
                            goto EXIT;
                        }
                    }
                    //用户车辆为一条数据时自动修改为默认车辆
                    var ii = mainsql.SqlExecuteScalar($"select count(1) from yonghuallusercar where car_userid='{user_id}'").ToInt32();
                    if (ii == 1)
                    {
                        int retint = mainsql.SqlExcuteNoReturn($"update  yonghuallusercar set isdefault=1 where car_userid='{user_id}'");
                    }
                    ret.Maplist_MapArgs.Add("Datas", mainsql.SqlExcuteWithReturn($"select * from {USERCAR} where car_userid='{user_id}' ;").ToModels());
                    ret.Map_Args["ErrorMsg"] = "操作成功";
                    mainsql.closesql();
                    tsall.Complete();
                    ret.Byte_Flag = (sbyte)1;
                }
            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误

            }

        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }
        #endregion
        #region 设置/取消车辆默认

        [WebMethod(Description = "设置/取消车辆默认")]
        public string Yonghu_CarSetDefault(string msg)
        {

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Maplist_MapArgs = new Dictionary<string, List<Dictionary<string, string>>>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);

            mysqlcli mainsql = new mysqlcli();

            try
            {
                using (TransactionScope tsall = new TransactionScope())
                {
                    mainsql.openShopServicesql();
                    var user_id = comrcv.Map_Args["user_id"];
                    var Sid = comrcv.Map_Args["sid"];

                    var ii = mainsql.SqlExecuteScalar($"select count(1) from yonghuallusercar where Sid='{Sid}' and car_userid='{user_id}' ").ToInt32();
                    if (ii == 0)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "车辆不存在";
                        goto EXIT;
                    }
                    //取消现有默认车辆
                    int retint = mainsql.SqlExcuteNoReturn($"update  yonghuallusercar set isdefault=0 where car_userid='{user_id}'");
                    if (retint > 0)
                    {
                        mainsql.SqlExcuteNoReturn($"update  yonghuallusercar set isdefault=1 where car_userid='{user_id}' and Sid='{Sid}'");
                    }
                    ret.Map_Args["ErrorMsg"] = "操作成功";
                    mainsql.closesql();
                    tsall.Complete();
                    ret.Byte_Flag = (sbyte)1;
                }
            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误

            }

        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }
        #endregion
        #region 删除

        [WebMethod(Description = "删除")]
        public string Yonghu_DelCar(string msg)
        {
            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Maplist_MapArgs = new Dictionary<string, List<Dictionary<string, string>>>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);
            mysqlcli mainsql = new mysqlcli();

            try
            {
                using (TransactionScope tsall = new TransactionScope())
                {
                    mainsql.openShopServicesql();
                    var Sid = comrcv.Map_Args["Sid"];
                    mainsql.SqlExcuteNoReturn($"delete from {USERCAR}  where Sid='{Sid}' ;");
                    ret.Map_Args["ErrorMsg"] = "操作成功";
                    mainsql.closesql();
                    tsall.Complete();
                    ret.Byte_Flag = (sbyte)1;
                }
            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误

            }
        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }

        #endregion

        #endregion

        #region 推广相关


        [WebMethod(Description = "返回小程序动态推广二维码")]
        public string All_GetXcxBmpbyid(string msg)
        {
            ILog loginfo = LogManager.GetLogger("LoggerJieKou");

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);

            try
            {
                mysqlcli mainsql = new mysqlcli();

                mainsql.openShopServicesql();

                string user_onlyid = comrcv.Map_Args["user_onlyid"];//用户的id
                var ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} where user_onlyid='{1}' ;", BIAOYONGHUUSER, user_onlyid));

                var tuiguangma = ds.Rows[0]["user_tuiguangid"].ToString();
                if (tuiguangma.Length < 4)
                {
                    tuiguangma = ds.Rows[0]["user_othertuiguangid"].ToString();
                }


                /*
                   string retstr1 = WebServiceShopping.wechartTools.GetXCXBMP(new WebServiceShopping.wechartTools.XcxBmpMsg()
                   { scene = "tuiguangma=" + tuiguangma });
                   */
                ret.Map_Args.Add("tuiguangma", tuiguangma);

                //    ret.Map_Args.Add("retstr", retstr1);
                ret.Byte_Flag = (sbyte)1;

            }
            catch (Exception ex)
            {

                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                loginfo.Info(ex);
            }

        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }

        [WebMethod(Description = "用户根据推广码绑定推广信息")]
        public string YongHu_SetTuiGuang(string msg)
        {
            ILog loginfo = LogManager.GetLogger("LoggerJieKou");

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);

            mysqlcli mainsql = new mysqlcli();

            try
            {
                string user_onlyid = comrcv.Map_Args["user_onlyid"];//用户的id
                string tuiguangma = comrcv.Map_Args["tuiguangma"];//对应的推广码
                loginfo.Info(tuiguangma + "+");
                using (TransactionScope tsall = new TransactionScope())
                {

                    mainsql.openShopServicesql();

                    var ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} WHERE user_onlyid = '{1}' ;", BIAOYONGHUUSER, user_onlyid));
                    string tuiguang = ds.Rows[0]["user_othertuiguangid"].ToString();
                    if (tuiguang == "")
                    {
                        mainsql.SqlExcuteWithReturn($"update {BIAOYONGHUUSER} set user_othertuiguangid = '{tuiguangma}' where user_onlyid='{user_onlyid}'");
                    }

                    mainsql.closesql();
                    tsall.Complete();
                    ret.Byte_Flag = (sbyte)1;
                }
            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                loginfo.Info(ex);
            }

        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }

        [WebMethod(Description = "用户查询自己的关系人员")]
        public string YongHu_GetTuiGuang(string msg)
        {
            ILog loginfo = LogManager.GetLogger("LoggerJieKou");

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);

            mysqlcli mainsql = new mysqlcli();

            mainsql.openShopServicesql();

            try
            {
                string user_onlyid = comrcv.Map_Args["user_onlyid"];//用户的id


                string sqlwhere = string.Format("WHERE user_onlyid = '{0}' ", user_onlyid);

                var ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} {1} ;", BIAOYONGHUUSER, sqlwhere));

                string mytuiguang = ds.Rows[0]["user_tuiguangid"].ToString();
                if (mytuiguang != "")
                {
                    sqlwhere = string.Format("WHERE user_othertuiguangid = '{0}' AND user_onlyid <> '{1}'  ", mytuiguang, user_onlyid);

                    ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} {1} ;", BIAOYONGHUUSER, sqlwhere));
                    ret.Maplist_MapArgs = new Dictionary<string, List<Dictionary<string, string>>>();
                    ret.Maplist_MapArgs.Add("Datas", ds.ToModels());
                }
                mainsql.closesql();

                ret.Byte_Flag = (sbyte)1;

            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                loginfo.Info(ex);
            }

        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }

        [WebMethod(Description = "用户查询自己的代理人员")]
        public string YongHu_GetDaiLi(string msg)
        {
            ILog loginfo = LogManager.GetLogger("LoggerJieKou");

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);

            mysqlcli mainsql = new mysqlcli();

            mainsql.openShopServicesql();

            try
            {
                string user_onlyid = comrcv.Map_Args["user_onlyid"];//用户的id


                string sqlwhere = string.Format("WHERE user_onlyid = '{0}' ", user_onlyid);

                var ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} {1} ;", BIAOYONGHUUSER, sqlwhere));
                int mylevel = ds.Rows[0]["user_tuiguanglevel"].ToInt32();
                mylevel++;
                string mytuiguang = ds.Rows[0]["user_tuiguangid"].ToString();
                if (mytuiguang != "")
                {
                    sqlwhere = string.Format("WHERE user_othertuiguangid = '{0}' AND user_tuiguanglevel='{1}'  ",
                        mytuiguang, mylevel);

                    ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} {1} ;", BIAOYONGHUUSER, sqlwhere));
                    ret.Maplist_MapArgs = new Dictionary<string, List<Dictionary<string, string>>>();
                    ret.Maplist_MapArgs.Add("Datas", ds.ToModels());
                }
                mainsql.closesql();

                ret.Byte_Flag = (sbyte)1;

            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                loginfo.Info(ex);
            }

        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }

        [WebMethod(Description = "查询自己的推广比例")]
        public string YongHu_GetTuiGuangBiLi(string msg)
        {
            ILog loginfo = LogManager.GetLogger("LoggerJieKou");

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);
            mysqlcli mainsql = new mysqlcli();
            mainsql.openShopServicesql();
            ret.Map_Args.Add("TuiGuangBiLi", "0");
            try
            {
                string user_onlyid = comrcv.Map_Args["user_onlyid"];//用户的id

                var ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} WHERE user_onlyid = '{1}' ;", BIAOYONGHUUSER, user_onlyid));
                string user_othertuiguangid = ds.Rows[0]["user_othertuiguangid"].ToString();
                string user_tuiguanglevel = ds.Rows[0]["user_tuiguanglevel"].ToString();
                if (user_tuiguanglevel == "1")
                {
                    ret.Map_Args["TuiGuangBiLi"] = ds.Rows[0]["user_tuiguangbili"].ToString();
                }
                else if (user_tuiguanglevel == "2")
                {
                    double bili1 = ds.Rows[0]["user_tuiguangbili"].ToDouble();
                    ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} WHERE user_tuiguangid = '{1}' ;", BIAOYONGHUUSER, user_othertuiguangid));
                    double bili2 = ds.Rows[0]["user_tuiguangbili"].ToDouble();
                    double overbili = bili1 * bili2;
                    overbili = Math.Round(overbili, 3);
                    ret.Map_Args["TuiGuangBiLi"] = overbili.ToString();
                }
                else if (user_tuiguanglevel == "3")
                {
                    double bili1 = ds.Rows[0]["user_tuiguangbili"].ToDouble();
                    ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} WHERE user_tuiguangid = '{1}' ;", BIAOYONGHUUSER, user_othertuiguangid));
                    double bili2 = ds.Rows[0]["user_tuiguangbili"].ToDouble();
                    user_othertuiguangid = ds.Rows[0]["user_othertuiguangid"].ToString();
                    ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} WHERE user_tuiguangid = '{1}' ;", BIAOYONGHUUSER, user_othertuiguangid));
                    double bili3 = ds.Rows[0]["user_tuiguangbili"].ToDouble();
                    double overbili = bili1 * bili2 * bili3;
                    overbili = Math.Round(overbili, 3);
                    ret.Map_Args["TuiGuangBiLi"] = overbili.ToString();
                }


                mainsql.closesql();

                ret.Byte_Flag = (sbyte)1;

            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                loginfo.Info(ex);
            }

        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }

        [WebMethod(Description = "用户升级自己关系为代理")]
        public string YongHu_SetDaiLi(string msg)
        {
            ILog loginfo = LogManager.GetLogger("LoggerJieKou");

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);

            mysqlcli mainsql = new mysqlcli();

            try
            {
                string user_onlyid = comrcv.Map_Args["user_onlyid"];//用户的id
                string otheruser_onlyid = comrcv.Map_Args["otheruser_onlyid"];//要升级的用户id
                string bili = comrcv.Map_Args["bili"];//对应的比例

                using (TransactionScope tsall = new TransactionScope())
                {

                    mainsql.openShopServicesql();

                    var ds = mainsql.SqlExcuteWithReturn(string.Format("select * from {0} WHERE user_onlyid = '{1}' ;", BIAOYONGHUUSER, user_onlyid));
                    int mylevel = ds.Rows[0]["user_tuiguanglevel"].ToInt32();
                    if (mylevel != 1 && mylevel != 2)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "您不能升级代理人";  //参数错误
                        goto EXIT;
                    }
                    mylevel++;
                    string tuiguangid = gettuiguangcount(mainsql);
                    mainsql.SqlExcuteNoReturn(string.Format(" update {0} set user_tuiguanglevel='{1}',user_tuiguangid='{2}' ,user_tuiguangbili='{3}'  WHERE user_onlyid = '{4}' ;",
                    BIAOYONGHUUSER, mylevel, tuiguangid, bili, otheruser_onlyid));


                    mainsql.closesql();
                    tsall.Complete();
                    ret.Byte_Flag = (sbyte)1;
                }
            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                loginfo.Info(ex);
            }

        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }

        [WebMethod(Description = "用户修改代理的比例")]
        public string YongHu_ChangeDaiLi(string msg)
        {
            ILog loginfo = LogManager.GetLogger("LoggerJieKou");

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);

            mysqlcli mainsql = new mysqlcli();

            try
            {

                string otheruser_onlyid = comrcv.Map_Args["otheruser_onlyid"];//用户id
                string bili = comrcv.Map_Args["bili"];//对应的比例

                using (TransactionScope tsall = new TransactionScope())
                {

                    mainsql.openShopServicesql();


                    mainsql.SqlExcuteNoReturn(string.Format(" update {0} set user_tuiguangbili='{1}'  WHERE user_onlyid = '{2}' ;",
                    BIAOYONGHUUSER, bili, otheruser_onlyid));


                    mainsql.closesql();
                    tsall.Complete();
                    ret.Byte_Flag = (sbyte)1;
                }
            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                loginfo.Info(ex);
            }

        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }



        #endregion

        #region 优惠券功能
        /*
         * yhq_type,0首页优惠券，1现金券，2折扣券，3满减券
         * yhq_zftype，0未使用，1已使用
         * 
         * */

        //获取优惠券列表信息
        [WebMethod(Description = "正式版本")]
        public string xcx_getuseryhq(string msg)
        {
            ILog logJieKou = LogManager.GetLogger("LoggerZhiFu");
            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv);
            mysqlcli mainsql = new mysqlcli();

            try
            {
                mainsql.openYongHuServicesql();

                string useronlyid = comrcv.Map_Args["userid"];
                //string useronlyid = "e60943f6-847c-4131-89dc-3e60909441ad";
                logJieKou.Info("获取优惠券信息-" + useronlyid);
                string sqlcmd = $"SELECT *  FROM s_coupon where user_id='{useronlyid}' order by coupon_createtime";
                var copons = mainsql.SqlExcuteWithReturn(sqlcmd).ToModels();
                ret.Map_Args.Add("AllCount", copons.Count.ToString());
                ret.List_MapArgs = new List<Dictionary<string, string>>();

                //获取修理厂信息
                var companys = new List<Dictionary<string, string>>();
                ret.Maplist_MapArgs = new Dictionary<string, List<Dictionary<string, string>>>();

                copons.ForEach(t =>
                {
                    //获取公司信息
                    if (!string.IsNullOrWhiteSpace(t["company_id"]))
                    {
                        if (!t["company_id"].Equals("all"))
                        {
                            var ids = t["company_id"].Split(',');

                            sqlcmd = $"select Group_CONCAT(user_companyname) as companyName,Group_CONCAT(user_id) as companyId from s_usercompany where user_id in ({string.Join(",", ids.Select(s => $"'{s}'"))})";

                            var res = mainsql.SqlExcuteWithReturn(sqlcmd).ToModels().FirstOrDefault();

                            t["companyName"] = res["companyName"];
                            t["companyId"] = res["companyId"];
                        }
                        else
                        {
                            t["companyName"] = "all";
                            t["companyId"] = "all";
                        }

                    }

                    //获取产品信息
                    if (!string.IsNullOrWhiteSpace(t["coupon_product_id"]))
                    {
                        if (!t["coupon_product_id"].Equals("all"))
                        {
                            var ids = t["coupon_product_id"].Split(',');
                            sqlcmd = $"select Group_CONCAT(commodity_name) as commodityName, Group_CONCAT(commodity_id) as commodityId from s_commodity where commodity_id in  ({string.Join(",", ids.Select(s => $"'{s}'"))})";

                            var res = mainsql.SqlExcuteWithReturn(sqlcmd).ToModels().FirstOrDefault();

                            t["commodityName"] = res["commodityName"];
                            t["commodityId"] = res["commodityId"];
                        }
                        else
                        {
                            t["commodityName"] = "all";
                            t["commodityId"] = "all";
                        }

                    }

                    //获取产品信息
                    if (!string.IsNullOrWhiteSpace(t["coupon_product_type"]))
                    {
                        if (!t["coupon_product_type"].Equals("all"))
                        {
                            var ids = t["coupon_product_type"].Split(',');
                            sqlcmd = $"select GROUP_CONCAT(commpdity_type_name) as commpdityTypeName,GROUP_CONCAT(commpdity_type_id) as commpdityTypeId from s_commpditytype where commpdity_type_id in({string.Join(",", ids.Select(s => $"'{s}'"))})";

                            var res = mainsql.SqlExcuteWithReturn(sqlcmd).ToModels().FirstOrDefault();

                            t["commpdityTypeName"] = res["commpdityTypeName"];
                            t["commpdityTypeId"] = res["commpdityTypeId"];
                        }
                        else
                        {
                            t["commpdityTypeName"] = "all";
                            t["commpdityTypeId"] = "all";
                        }
                    }

                });

                ret.Maplist_MapArgs.Add("copons", copons);
            }
            catch (Exception ex)
            {
                logJieKou.Info("获取优惠券信息-" + ex.Message);
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                goto EXIT;
            }
            ret.Byte_Flag = (sbyte)1;
        EXIT:
            mainsql.closesql();
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret);
            string retstr = Convert.ToBase64String(retb);
            return retstr;

        }

        //支付获取优惠券列表信息
        //[WebMethod(Description = "正式版本")]
        //public string xcx_zfgetuseryhq(string msg)
        //{
        //    ILog logJieKou = LogManager.GetLogger("LoggerZhiFu");
        //    ComThriftMsg ret = new ComThriftMsg();
        //    ret.Byte_Flag = (sbyte)-1;
        //    ret.Map_Args = new Dictionary<string, string>();
        //    ret.Map_Args.Add("ErrorMsg", "服务器异常");
        //    byte[] bytrcv = Convert.FromBase64String(msg);
        //    ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv);
        //    mysqlcli mainsql = new mysqlcli();

        //    try
        //    {
        //        string useronlyid = comrcv.Map_Args["userid"];
        //        string cost = comrcv.Map_Args["cost"];
        //        string type = comrcv.Map_Args["type"];//1团购，2修车

        //        double dbcost = 0;
        //        double.TryParse(cost, out dbcost);

        //        logJieKou.Info("支付获取优惠券列表信息-" + useronlyid);

        //        mainsql.openYongHuServicesql();
        //        string sqlcmd = string.Format("SELECT *  FROM {0} where yhq_useronlyid='{1}' and yhq_status='未使用'  ORDER BY yhq_createtime  ;",
        //            BIAOALLYOUHUIQUAN, useronlyid);
        //        DataTable ds = mainsql.SqlExcuteWithReturn(sqlcmd);
        //        ret.Map_Args.Add("AllCount", ds.Rows.Count.ToString());
        //        ret.List_MapArgs = new List<Dictionary<string, string>>();
        //        if (ds.Rows.Count != 0)
        //        {
        //            foreach (DataRow row in ds.Rows)
        //            {
        //                double dbyhq_amount = row["yhq_amount"].ToDouble();
        //                if (dbcost >= dbyhq_amount)
        //                {

        //                    Dictionary<string, string> newNetImple = new Dictionary<string, string>();
        //                    foreach (DataColumn dl in ds.Columns)
        //                    {

        //                        newNetImple.Add(dl.ColumnName, row[dl.ColumnName].ToString());
        //                    }
        //                    ret.List_MapArgs.Add(newNetImple);
        //                }
        //            }
        //        }
        //        mainsql.closesql();
        //    }
        //    catch (Exception ex)
        //    {
        //        logJieKou.Info("获取优惠券信息-" + ex.Message);
        //        ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
        //        mainsql.closesql();
        //        goto EXIT;
        //    }
        //    ret.Byte_Flag = (sbyte)1;
        //    EXIT:
        //    byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret);
        //    string retstr = Convert.ToBase64String(retb);
        //    return retstr;

        //}

        //用户获取首页优惠券
        [WebMethod(Description = "正式版本")]
        public string xcx_usergetshouyeyhq(string msg)
        {
            ILog logJieKou = LogManager.GetLogger("LoggerZhiFu");
            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv);
            mysqlcli mainsql = new mysqlcli();
            try
            {
                string user_id = comrcv.Map_Args["user_id"];
                string user_phone = comrcv.Map_Args["user_phone"];//15023196534,15023196535


                logJieKou.Info("用户获取首页优惠券-");
                using (TransactionScope tsall = new TransactionScope())
                {
                    mainsql.openYongHuServicesql();


                    //string sqlcmd = string.Format("SELECT *  FROM {0} where yhq_useronlyid='{1}' AND yhq_type='0' ;",
                    //    BIAOALLYOUHUIQUAN, user_id);
                    //var ds = mainsql.SqlExcuteWithReturn(sqlcmd);
                    //if (ds.Rows.Count != 0)
                    //{
                    //    mainsql.closesql();
                    //    ret.Map_Args["ErrorMsg"] = "您已经领取过新用户优惠券了";
                    //    goto EXIT;
                    //}

                    // DateTime.Now.AddMonths(2).ToString("yyyy-MM-dd HH:mm:ss")
                    //string yhqid = GetYHQID();

                    //sqlcmd = string.Format("INSERT INTO {0} (yhq_yhqid,yhq_userphone,yhq_useronlyid,yhq_zftype,yhq_type ," +
                    //"yhq_status,yhq_amount,yhq_endtime,yhq_shuoming,yhq_createtime)" +
                    //" VALUES ('{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}')",
                    //BIAOALLYOUHUIQUAN, yhqid, user_phone, user_id,
                    //"0", "0", "未使用", "50", "2022-10-31 23:59:59"
                    //, "平台现金券50元", DateTime.Now.ToString("yyyy-MM-dd"));
                    //int sqlret = mainsql.SqlExcuteNoReturn(sqlcmd);


                    //yhqid = GetYHQID();

                    //sqlcmd = string.Format("INSERT INTO {0} (yhq_yhqid,yhq_userphone,yhq_useronlyid,yhq_zftype,yhq_type ," +
                    //"yhq_status,yhq_amount,yhq_endtime,yhq_shuoming,yhq_createtime)" +
                    //" VALUES ('{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}')",
                    //BIAOALLYOUHUIQUAN, yhqid, user_phone, user_id,
                    //"0", "0", "未使用", "15", "2022-10-31 23:59:59"
                    // , "平台现金券15元", DateTime.Now.ToString("yyyy-MM-dd"));
                    //sqlret = mainsql.SqlExcuteNoReturn(sqlcmd);


                    //mainsql.closesql();
                    //tsall.Complete();
                }
            }
            catch (Exception ex)
            {
                logJieKou.Info("用户获取首页优惠券-" + ex.Message);
                mainsql.closesql();

                goto EXIT;
            }
            ret.Byte_Flag = (sbyte)1;
        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret);
            string retstr = Convert.ToBase64String(retb);
            return retstr;

        }

        //用户选择优惠券
        [WebMethod(Description = "正式版本")]
        public string xcx_getuserselectyhq(string msg)
        {
            ILog logJieKou = LogManager.GetLogger("LoggerZhiFu");
            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv);
            mysqlcli mainsql = new mysqlcli();

            try
            {
                string useronlyid = comrcv.Map_Args["userid"];
                string yhqid = comrcv.Map_Args["yhqid"];
                string repair_id = comrcv.Map_Args["repair_id"];
                string cost = comrcv.Map_Args["cost"];
                double dbcost = 0;
                double.TryParse(cost, out dbcost);
                double yhqcost = 0;
                logJieKou.Info("获取优惠券信息-" + useronlyid);

                mainsql.openYongHuServicesql();
                string sqlcmd = string.Format("SELECT *  FROM {0} where yhq_useronlyid='{1}' AND Sid='{2}' AND yhq_zftype='0'   ;",
                    BIAOALLYOUHUIQUAN, useronlyid, yhqid);
                DataTable ds = mainsql.SqlExcuteWithReturn(sqlcmd);
                if (ds.Rows.Count == 0)
                {
                    mainsql.closesql();
                    ret.Map_Args["ErrorMsg"] = "没有此优惠券";
                    goto EXIT;
                }
                DataRow yhqrow = ds.Rows[0] as DataRow;

                double.TryParse(yhqrow["yhq_amount"].ToString(), out yhqcost);

                dbcost = dbcost - yhqcost;
                if (dbcost < 0)
                {
                    dbcost = 0;
                }

                ret.Map_Args.Add("newcost", dbcost.ToString());
                mainsql.closesql();
            }
            catch (Exception ex)
            {
                logJieKou.Info("获取优惠券信息-" + ex.Message);
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                mainsql.closesql();
                goto EXIT;
            }
            ret.Byte_Flag = (sbyte)1;
        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret);
            string retstr = Convert.ToBase64String(retb);
            return retstr;

        }

        //获取分享页面参数
        [WebMethod(Description = "正式版本")]
        public string xcx_fenxiangcanshu(string msg)
        {
            ILog logJieKou = LogManager.GetLogger("LoggerZhiFu");
            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv);


            try
            {

                logJieKou.Info("获取分享页面参数-");
                ret.Map_Args.Add("fenxiangjine", "40");

            }
            catch (Exception ex)
            {
                logJieKou.Info("获取分享页面参数-" + ex.Message);
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误

                goto EXIT;
            }
            ret.Byte_Flag = (sbyte)1;
        EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret);
            string retstr = Convert.ToBase64String(retb);
            return retstr;

        }


        #endregion



    }
}
